locked
response object to download a file RRS feed

  • Question

  • User1064255541 posted
    I have created a method to download a file from a server using webservice. Everything is working, except the last step to show the dialogbox to 'save as' or 'run' or 'cancel' the file. The downloaded file is on the local harddisk in the folder: c:/windows/temp/upload . I have tested it with a Word .doc extension. Now i have the following code: dim filename as string = "c:/windows/temp/upload/testing.doc" objFileInfo = New System.IO.FileInfo(fileName) Response.AddHeader("Content-Disposition", "attachment; filename=" & fileName) Response.AddHeader("Content-Length", objFileInfo.Length.ToString()) Response.ContentType = "application/octet-stream" Response.WriteFile(objFileInfo.FullName) Response.Flush() Response.Clear() Response.end() I get a dialog which tells me i if I want to download or run an unknown file. Name = the name of the page of which im executing the script (so this is wrong maybe, but where can i change that?) type = html-document, The host = localhost. Datatype = unknown somebody can help me?
    Friday, March 18, 2005 9:42 AM

All replies

  • User371668647 posted
    Should just need: Response.AddHeader("Content-Type", "application/ms-word") I think the type is right, but you might want to check it...
    Saturday, March 19, 2005 10:04 PM
  • User1064255541 posted
    Im have tried some things out and for now 2 questions exists. fileName = only the name of the fileName en not the whole path of the file. The contentype have always to be set manually expicit?. On MSDN i have read MIME types are recognized automaticly, is this true? And does that mean i dont have to set a contenttype? In my project the chanse exists that several filetypes will be downloaded, so i must set dynamicly the contenttype, which depends on the filetype thats selected. But i think its not the right way to make a 'select case' with all MIME-types and set the contenttype on this way. Always on the last step of the project it gives an exception when the method Response.End() is called. How to solve this? tia
    Sunday, March 20, 2005 8:07 AM
  • User371668647 posted
    Try this: Response.Clear() dim filename as string = "c:/windows/temp/upload/testing.doc" objFileInfo = New System.IO.FileInfo(fileName) Response.AddHeader("Content-Disposition", "attachment; filename=" & fileName.Substring(fileName.LastIndexOf("/"))) Response.AddHeader("Content-Length", objFileInfo.Length.ToString()) Response.ContentType = "application/octet-stream" Response.WriteFile(objFileInfo.FullName) Response.End()
    Monday, March 21, 2005 7:27 AM