File Download from Network Share

Discussion in 'ASP .Net' started by =?Utf-8?B?QmFyZW4=?=, Jun 1, 2005.

  1. Hi!

    I am using impersonate="true" to upload and download files from a network
    share.

    I have created common users on both the webserver and the file server. The
    user has permission to the files server folder.
    I am able to upload the files into the fileserver, but while downloading the
    same i am getting error "file doesn't exist" and the path it shows is
    localhost temporary internet files.

    Please help

    Thanks in advance,
     
    =?Utf-8?B?QmFyZW4=?=, Jun 1, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?QmFyZW4=?=

    Patrice Guest

    Is the "localhost" location correct ? If not you'll have likely to fix how
    the path is build

    How do you want to download this file ? Do you want a direct link to a file
    share ? My personal preference is to stream the file using the server side
    page (using Response.WriteFile).

    Patrice
    --

    "Baren" <> a écrit dans le message de
    news:...
    > Hi!
    >
    > I am using impersonate="true" to upload and download files from a network
    > share.
    >
    > I have created common users on both the webserver and the file server. The
    > user has permission to the files server folder.
    > I am able to upload the files into the fileserver, but while downloading

    the
    > same i am getting error "file doesn't exist" and the path it shows is
    > localhost temporary internet files.
    >
    > Please help
    >
    > Thanks in advance,
     
    Patrice, Jun 1, 2005
    #2
    1. Advertising

  3. In addition, have a look at using the WebClient class in any event. I have
    experienced it's performance to be far superior to any of the other methods
    of moving files.

    Br,

    Mark.

    "Patrice" <> wrote in message
    news:...
    > Is the "localhost" location correct ? If not you'll have likely to fix how
    > the path is build
    >
    > How do you want to download this file ? Do you want a direct link to a
    > file
    > share ? My personal preference is to stream the file using the server side
    > page (using Response.WriteFile).
    >
    > Patrice
    > --
    >
    > "Baren" <> a écrit dans le message de
    > news:...
    >> Hi!
    >>
    >> I am using impersonate="true" to upload and download files from a network
    >> share.
    >>
    >> I have created common users on both the webserver and the file server.
    >> The
    >> user has permission to the files server folder.
    >> I am able to upload the files into the fileserver, but while downloading

    > the
    >> same i am getting error "file doesn't exist" and the path it shows is
    >> localhost temporary internet files.
    >>
    >> Please help
    >>
    >> Thanks in advance,

    >
    >
     
    Mark Broadbent, Jun 1, 2005
    #3
  4. Hi! Patrice,

    Thanks for the response. I am using filestream to read the file like
    Dim strFilePath As String
    Dim strFileName As String
    Dim fsFile As FileStream
    Dim strFileExtn As String
    Dim strMIMEType As String
    Dim lnFileSize As Long

    strFileName = "XXXX_050601105406_DIA.JPG"
    strFilePath = "\\<Network Server Name>\<folder
    Name>\XXXX_050601105406_DIA.JPG"
    strFileExtn = strFileName.Substring(strFileName.LastIndexOf(".") + 1)

    Select Case strFileExtn.ToUpper()
    Case "AU", "SND"
    strMIMEType = "audio/basic"
    Case "WAV"
    strMIMEType = "audio/wav"
    Case "RA", "RM", "RAM"
    strMIMEType = "audio/x-pn-realaudio"
    Case "MID", "MIDI"
    strMIMEType = "audio/x-midi"
    Case "MP3"
    strMIMEType = "audio/mp3"
    Case "M3U"
    strMIMEType = "audio/m3u"
    Case "TXT", "TEXT", "VBS", "ASP", "CGI", "PL", "NFO", "ME", "DTD"
    strMIMEType = "text/plain"
    Case "HTM", "HTML", "HTA", "HTX", "MHT"
    strMIMEType = "text/html"
    Case "JS"
    strMIMEType = "text/javascript"
    Case "CSS"
    strMIMEType = "text/css"
    Case "PDF"
    strMIMEType = "application/pdf"
    Case "RTF"
    strMIMEType = "application/rtf"
    Case "XML", "XSL", "XSLT"
    strMIMEType = "text/xml"
    Case "WPD"
    strMIMEType = "application/wordperfect"
    Case "WRI"
    strMIMEType = "application/mswrite"
    Case "XLS", "XLS3", "XLS4", "XLS5", "XLW"
    strMIMEType = "application/msexcel"
    Case "DOC"
    strMIMEType = "application/msword"
    Case "PPT", "PPS"
    strMIMEType = "application/mspowerpoint"
    Case "WML"
    strMIMEType = "text/vnd.wap.wml"
    Case "WMLS"
    strMIMEType = "text/vnd.wap.wmlscript"
    Case "WBMP"
    strMIMEType = "image/vnd.wap.wbmp"
    Case "WMLC"
    strMIMEType = "application/vnd.wap.wmlc"
    Case "WMLSC"
    strMIMEType = "application/vnd.wap.wmlscriptc"
    Case "GIF"
    strMIMEType = "image/gif"
    Case "JPG", "JPE", "JPEG"
    strMIMEType = "image/jpeg"
    Case "PNG"
    strMIMEType = "image/png"
    Case "BMP"
    strMIMEType = "image/bmp"
    Case "TIF", "TIFF"
    strMIMEType = "image/tiff"
    Case "AI", "EPS", "PS"
    strMIMEType = "application/postscript"
    Case "ASF"
    strMIMEType = "video/x-ms-asf"
    Case "AVI"
    strMIMEType = "video/avi"
    Case "MPG", "MPEG"
    strMIMEType = "video/mpeg"
    Case "QT", "MOV", "QTVR"
    strMIMEType = "video/quicktime"
    Case "SWA"
    strMIMEType = "application/x-director"
    Case "SWF"
    strMIMEType = "application/x-shockwave-flash"
    Case "ZIP"
    strMIMEType = "application/x-zip-compressed"
    Case "GZ"
    strMIMEType = "application/x-gzip"
    Case "RAR"
    strMIMEType = "application/x-rar-compressed"
    Case "COM", "EXE", "DLL", "OCX"
    strMIMEType = "application/octet-stream"
    Case Else
    strMIMEType = "application/octet-stream"
    End Select
    Response.Clear()
    Response.ContentType = strMIMEType
    Response.AddHeader("content-disposition", "attachment;filename=" +
    strFileName)
    fsFile = New FileStream(strFilePath, FileMode.Open)
    lnFileSize = fsFile.Length
    Dim getContent(CInt(lnFileSize)) As Byte
    fsFile.Read(getContent, 0, CInt(fsFile.Length))
    fsFile.Close()
    Response.BinaryWrite(getContent)
    Response.End()

    It's working fine when i am viewing a page without user authentications.

    In my project, different user's have username and encrypted passwords. On
    valid authentication user is allowed to go into the site. Here the problem
    occours when the user is trying to view the files, whereas if user downloads
    the file, its downloads properly with the correct file.

    Thanks,
    Baren



    "Patrice" wrote:

    > Is the "localhost" location correct ? If not you'll have likely to fix how
    > the path is build
    >
    > How do you want to download this file ? Do you want a direct link to a file
    > share ? My personal preference is to stream the file using the server side
    > page (using Response.WriteFile).
    >
    > Patrice
    > --
    >
    > "Baren" <> a écrit dans le message de
    > news:...
    > > Hi!
    > >
    > > I am using impersonate="true" to upload and download files from a network
    > > share.
    > >
    > > I have created common users on both the webserver and the file server. The
    > > user has permission to the files server folder.
    > > I am able to upload the files into the fileserver, but while downloading

    > the
    > > same i am getting error "file doesn't exist" and the path it shows is
    > > localhost temporary internet files.
    > >
    > > Please help
    > >
    > > Thanks in advance,

    >
    >
    >
     
    =?Utf-8?B?QmFyZW4=?=, Jun 2, 2005
    #4
  5. =?Utf-8?B?QmFyZW4=?=

    Patrice Guest

    What is the exact error ? I don't understand what you mean by "the path it
    shows is localhost temporary internet files". Where do you see this name ?

    For now it looks like a permission problem. Double check impersonated users
    are allowed to read from this location you could,have a test page dthat even
    doesn't stream)...

    To stream the file you could use Response.Write. Not sure but the mimetype
    could be useless (AFAIK it uses the file extension when using
    "attachment;filename=..." in the header...

    Good luck.

    --

    "Baren" <> a écrit dans le message de
    news:...
    > Hi! Patrice,
    >
    > Thanks for the response. I am using filestream to read the file like
    > Dim strFilePath As String
    > Dim strFileName As String
    > Dim fsFile As FileStream
    > Dim strFileExtn As String
    > Dim strMIMEType As String
    > Dim lnFileSize As Long
    >
    > strFileName = "XXXX_050601105406_DIA.JPG"
    > strFilePath = "\\<Network Server Name>\<folder
    > Name>\XXXX_050601105406_DIA.JPG"
    > strFileExtn = strFileName.Substring(strFileName.LastIndexOf(".") +

    1)
    >
    > Select Case strFileExtn.ToUpper()
    > Case "AU", "SND"
    > strMIMEType = "audio/basic"
    > Case "WAV"
    > strMIMEType = "audio/wav"
    > Case "RA", "RM", "RAM"
    > strMIMEType = "audio/x-pn-realaudio"
    > Case "MID", "MIDI"
    > strMIMEType = "audio/x-midi"
    > Case "MP3"
    > strMIMEType = "audio/mp3"
    > Case "M3U"
    > strMIMEType = "audio/m3u"
    > Case "TXT", "TEXT", "VBS", "ASP", "CGI", "PL", "NFO", "ME",

    "DTD"
    > strMIMEType = "text/plain"
    > Case "HTM", "HTML", "HTA", "HTX", "MHT"
    > strMIMEType = "text/html"
    > Case "JS"
    > strMIMEType = "text/javascript"
    > Case "CSS"
    > strMIMEType = "text/css"
    > Case "PDF"
    > strMIMEType = "application/pdf"
    > Case "RTF"
    > strMIMEType = "application/rtf"
    > Case "XML", "XSL", "XSLT"
    > strMIMEType = "text/xml"
    > Case "WPD"
    > strMIMEType = "application/wordperfect"
    > Case "WRI"
    > strMIMEType = "application/mswrite"
    > Case "XLS", "XLS3", "XLS4", "XLS5", "XLW"
    > strMIMEType = "application/msexcel"
    > Case "DOC"
    > strMIMEType = "application/msword"
    > Case "PPT", "PPS"
    > strMIMEType = "application/mspowerpoint"
    > Case "WML"
    > strMIMEType = "text/vnd.wap.wml"
    > Case "WMLS"
    > strMIMEType = "text/vnd.wap.wmlscript"
    > Case "WBMP"
    > strMIMEType = "image/vnd.wap.wbmp"
    > Case "WMLC"
    > strMIMEType = "application/vnd.wap.wmlc"
    > Case "WMLSC"
    > strMIMEType = "application/vnd.wap.wmlscriptc"
    > Case "GIF"
    > strMIMEType = "image/gif"
    > Case "JPG", "JPE", "JPEG"
    > strMIMEType = "image/jpeg"
    > Case "PNG"
    > strMIMEType = "image/png"
    > Case "BMP"
    > strMIMEType = "image/bmp"
    > Case "TIF", "TIFF"
    > strMIMEType = "image/tiff"
    > Case "AI", "EPS", "PS"
    > strMIMEType = "application/postscript"
    > Case "ASF"
    > strMIMEType = "video/x-ms-asf"
    > Case "AVI"
    > strMIMEType = "video/avi"
    > Case "MPG", "MPEG"
    > strMIMEType = "video/mpeg"
    > Case "QT", "MOV", "QTVR"
    > strMIMEType = "video/quicktime"
    > Case "SWA"
    > strMIMEType = "application/x-director"
    > Case "SWF"
    > strMIMEType = "application/x-shockwave-flash"
    > Case "ZIP"
    > strMIMEType = "application/x-zip-compressed"
    > Case "GZ"
    > strMIMEType = "application/x-gzip"
    > Case "RAR"
    > strMIMEType = "application/x-rar-compressed"
    > Case "COM", "EXE", "DLL", "OCX"
    > strMIMEType = "application/octet-stream"
    > Case Else
    > strMIMEType = "application/octet-stream"
    > End Select
    > Response.Clear()
    > Response.ContentType = strMIMEType
    > Response.AddHeader("content-disposition", "attachment;filename=" +
    > strFileName)
    > fsFile = New FileStream(strFilePath, FileMode.Open)
    > lnFileSize = fsFile.Length
    > Dim getContent(CInt(lnFileSize)) As Byte
    > fsFile.Read(getContent, 0, CInt(fsFile.Length))
    > fsFile.Close()
    > Response.BinaryWrite(getContent)
    > Response.End()
    >
    > It's working fine when i am viewing a page without user authentications.
    >
    > In my project, different user's have username and encrypted passwords. On
    > valid authentication user is allowed to go into the site. Here the problem
    > occours when the user is trying to view the files, whereas if user

    downloads
    > the file, its downloads properly with the correct file.
    >
    > Thanks,
    > Baren
    >
    >
    >
    > "Patrice" wrote:
    >
    > > Is the "localhost" location correct ? If not you'll have likely to fix

    how
    > > the path is build
    > >
    > > How do you want to download this file ? Do you want a direct link to a

    file
    > > share ? My personal preference is to stream the file using the server

    side
    > > page (using Response.WriteFile).
    > >
    > > Patrice
    > > --
    > >
    > > "Baren" <> a écrit dans le message de
    > > news:...
    > > > Hi!
    > > >
    > > > I am using impersonate="true" to upload and download files from a

    network
    > > > share.
    > > >
    > > > I have created common users on both the webserver and the file server.

    The
    > > > user has permission to the files server folder.
    > > > I am able to upload the files into the fileserver, but while

    downloading
    > > the
    > > > same i am getting error "file doesn't exist" and the path it shows is
    > > > localhost temporary internet files.
    > > >
    > > > Please help
    > > >
    > > > Thanks in advance,

    > >
    > >
    > >
     
    Patrice, Jun 2, 2005
    #5
  6. Hi! Patrice

    Thanks for the reply. I am able to solve the problem. I had this code
    Response.Cache.SetCacheability(HttpCacheability.NoCache) which was causing
    the problem. Now i commented the line and its working fine.

    Thanks again
    Baren

    "Patrice" wrote:

    >
    > What is the exact error ? I don't understand what you mean by "the path it
    > shows is localhost temporary internet files". Where do you see this name ?
    >
    > For now it looks like a permission problem. Double check impersonated users
    > are allowed to read from this location you could,have a test page dthat even
    > doesn't stream)...
    >
    > To stream the file you could use Response.Write. Not sure but the mimetype
    > could be useless (AFAIK it uses the file extension when using
    > "attachment;filename=..." in the header...
    >
    > Good luck.
    >
    > --
    >
    > "Baren" <> a écrit dans le message de
    > news:...
    > > Hi! Patrice,
    > >
    > > Thanks for the response. I am using filestream to read the file like
    > > Dim strFilePath As String
    > > Dim strFileName As String
    > > Dim fsFile As FileStream
    > > Dim strFileExtn As String
    > > Dim strMIMEType As String
    > > Dim lnFileSize As Long
    > >
    > > strFileName = "XXXX_050601105406_DIA.JPG"
    > > strFilePath = "\\<Network Server Name>\<folder
    > > Name>\XXXX_050601105406_DIA.JPG"
    > > strFileExtn = strFileName.Substring(strFileName.LastIndexOf(".") +

    > 1)
    > >
    > > Select Case strFileExtn.ToUpper()
    > > Case "AU", "SND"
    > > strMIMEType = "audio/basic"
    > > Case "WAV"
    > > strMIMEType = "audio/wav"
    > > Case "RA", "RM", "RAM"
    > > strMIMEType = "audio/x-pn-realaudio"
    > > Case "MID", "MIDI"
    > > strMIMEType = "audio/x-midi"
    > > Case "MP3"
    > > strMIMEType = "audio/mp3"
    > > Case "M3U"
    > > strMIMEType = "audio/m3u"
    > > Case "TXT", "TEXT", "VBS", "ASP", "CGI", "PL", "NFO", "ME",

    > "DTD"
    > > strMIMEType = "text/plain"
    > > Case "HTM", "HTML", "HTA", "HTX", "MHT"
    > > strMIMEType = "text/html"
    > > Case "JS"
    > > strMIMEType = "text/javascript"
    > > Case "CSS"
    > > strMIMEType = "text/css"
    > > Case "PDF"
    > > strMIMEType = "application/pdf"
    > > Case "RTF"
    > > strMIMEType = "application/rtf"
    > > Case "XML", "XSL", "XSLT"
    > > strMIMEType = "text/xml"
    > > Case "WPD"
    > > strMIMEType = "application/wordperfect"
    > > Case "WRI"
    > > strMIMEType = "application/mswrite"
    > > Case "XLS", "XLS3", "XLS4", "XLS5", "XLW"
    > > strMIMEType = "application/msexcel"
    > > Case "DOC"
    > > strMIMEType = "application/msword"
    > > Case "PPT", "PPS"
    > > strMIMEType = "application/mspowerpoint"
    > > Case "WML"
    > > strMIMEType = "text/vnd.wap.wml"
    > > Case "WMLS"
    > > strMIMEType = "text/vnd.wap.wmlscript"
    > > Case "WBMP"
    > > strMIMEType = "image/vnd.wap.wbmp"
    > > Case "WMLC"
    > > strMIMEType = "application/vnd.wap.wmlc"
    > > Case "WMLSC"
    > > strMIMEType = "application/vnd.wap.wmlscriptc"
    > > Case "GIF"
    > > strMIMEType = "image/gif"
    > > Case "JPG", "JPE", "JPEG"
    > > strMIMEType = "image/jpeg"
    > > Case "PNG"
    > > strMIMEType = "image/png"
    > > Case "BMP"
    > > strMIMEType = "image/bmp"
    > > Case "TIF", "TIFF"
    > > strMIMEType = "image/tiff"
    > > Case "AI", "EPS", "PS"
    > > strMIMEType = "application/postscript"
    > > Case "ASF"
    > > strMIMEType = "video/x-ms-asf"
    > > Case "AVI"
    > > strMIMEType = "video/avi"
    > > Case "MPG", "MPEG"
    > > strMIMEType = "video/mpeg"
    > > Case "QT", "MOV", "QTVR"
    > > strMIMEType = "video/quicktime"
    > > Case "SWA"
    > > strMIMEType = "application/x-director"
    > > Case "SWF"
    > > strMIMEType = "application/x-shockwave-flash"
    > > Case "ZIP"
    > > strMIMEType = "application/x-zip-compressed"
    > > Case "GZ"
    > > strMIMEType = "application/x-gzip"
    > > Case "RAR"
    > > strMIMEType = "application/x-rar-compressed"
    > > Case "COM", "EXE", "DLL", "OCX"
    > > strMIMEType = "application/octet-stream"
    > > Case Else
    > > strMIMEType = "application/octet-stream"
    > > End Select
    > > Response.Clear()
    > > Response.ContentType = strMIMEType
    > > Response.AddHeader("content-disposition", "attachment;filename=" +
    > > strFileName)
    > > fsFile = New FileStream(strFilePath, FileMode.Open)
    > > lnFileSize = fsFile.Length
    > > Dim getContent(CInt(lnFileSize)) As Byte
    > > fsFile.Read(getContent, 0, CInt(fsFile.Length))
    > > fsFile.Close()
    > > Response.BinaryWrite(getContent)
    > > Response.End()
    > >
    > > It's working fine when i am viewing a page without user authentications.
    > >
    > > In my project, different user's have username and encrypted passwords. On
    > > valid authentication user is allowed to go into the site. Here the problem
    > > occours when the user is trying to view the files, whereas if user

    > downloads
    > > the file, its downloads properly with the correct file.
    > >
    > > Thanks,
    > > Baren
    > >
    > >
    > >
    > > "Patrice" wrote:
    > >
    > > > Is the "localhost" location correct ? If not you'll have likely to fix

    > how
    > > > the path is build
    > > >
    > > > How do you want to download this file ? Do you want a direct link to a

    > file
    > > > share ? My personal preference is to stream the file using the server

    > side
    > > > page (using Response.WriteFile).
    > > >
    > > > Patrice
    > > > --
    > > >
    > > > "Baren" <> a écrit dans le message de
    > > > news:...
    > > > > Hi!
    > > > >
    > > > > I am using impersonate="true" to upload and download files from a

    > network
    > > > > share.
    > > > >
    > > > > I have created common users on both the webserver and the file server.

    > The
    > > > > user has permission to the files server folder.
    > > > > I am able to upload the files into the fileserver, but while

    > downloading
    > > > the
    > > > > same i am getting error "file doesn't exist" and the path it shows is
    > > > > localhost temporary internet files.
    > > > >
    > > > > Please help
    > > > >
    > > > > Thanks in advance,
    > > >
    > > >
    > > >

    >
    >
    >
     
    =?Utf-8?B?QmFyZW4=?=, Jun 3, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jay
    Replies:
    2
    Views:
    932
    Peter O'Reilly
    Nov 21, 2003
  2. john smith
    Replies:
    0
    Views:
    451
    john smith
    Jan 6, 2004
  3. =?Utf-8?B?QW5kcmU=?=

    How to create file on network share from ASP.NET

    =?Utf-8?B?QW5kcmU=?=, Jul 20, 2005, in forum: ASP .Net
    Replies:
    12
    Views:
    8,254
    homertbush
    Mar 5, 2008
  4. Saraswati lakki
    Replies:
    0
    Views:
    1,371
    Saraswati lakki
    Jan 6, 2012
  5. Matt Royer

    Open file from network share

    Matt Royer, Nov 12, 2010, in forum: Ruby
    Replies:
    0
    Views:
    202
    Matt Royer
    Nov 12, 2010
Loading...

Share This Page