View Full Version : File access

02-15-2007, 03:08 AM
I have a code which is working fine locally

I browse for an image file -
<input id="FileToSave" type="file" name="FileToSave" runat="server">

Then I get the file name and upload it to the server with no problem
Dim strFileName As String = FileToSave.PostedFile.FileName

Uploading works fine on the server too.
But when I wish to check file properties (get width/height, resize, create a thumbnail), If File.Exists(strFileName) always return false.

Again it works locally but not on the server. File exists, the path is correct, security access is set to Full. What could be wrong? Why does the server upload files but can't read them?

02-15-2007, 06:25 AM
can you post some of your code that you are using to read the file?



02-15-2007, 12:52 PM
Here is my complete code -

Dim strFileName As String = FileToSave.PostedFile.FileName
Dim img1, objThumbnail As Image

If File.Exists(strFileName) Then
img1 = Image.FromFile(strFileName)
Dim strFileName1 As String = strFileName.Replace("\", "/")
img1 = Image.FromFile(strFileName1)
Catch ex1 As Exception
lblErr.Text = "Error: " & ex1.Message & ", File: " & strFileName
Exit Sub
End Try
End Try

Dim ratio As Single = img1.Height / 100
Dim wid As Integer = img1.Width / ratio
objThumbnail = img1.GetThumbnailImage(wid, 100, Nothing, System.IntPtr.Zero)
Response.ContentType = "image/jpeg"

Dim fn As String = "img" & Now.Year & Now.Month & Now.Day & Now.Hour & Now.Minute & Now.Second & Now.Millisecond
Session("img") = fn & strFileName.Substring(strFileName.Length - 4)
Dim fn1 = Constants.path & "trading/thumb/" & fn & ".jpg"
fn = Constants.path & "trading/" & Session("img")
objThumbnail.Save(fn1, Imaging.ImageFormat.Jpeg)

lblErr.Text = "Uploaded."
Catch ex2 As Exception
lblErr.Text = "Error while uploading. Try Again: " & ex2.Message
End Try
lblErr.Text = "File doesn't exist: " & strFileName
End If
End Sub

Again everything works fine locally !!!
Uploading itself works on the server too but I can't make 3rd line to work on the server ("File doesn't exist).

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum