Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: File access

  1. #1
    New Coder
    Join Date
    Jun 2003
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    File access

    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?

  • #2
    New Coder
    Join Date
    Jan 2003
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts
    can you post some of your code that you are using to read the file?

    Thanks,

    thomas

  • #3
    New Coder
    Join Date
    Jun 2003
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is my complete code -

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

    If File.Exists(strFileName) Then
    Try
    img1 = Image.FromFile(strFileName)
    Catch
    Try
    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)
    objThumbnail.Dispose()
    img1.Dispose()

    Try
    FileToSave.PostedFile.SaveAs(fn)
    lblErr.Text = "Uploaded."
    Catch ex2 As Exception
    lblErr.Text = "Error while uploading. Try Again: " & ex2.Message
    End Try
    Else
    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).


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •