Downloading File
-
Hi... I am making a website in asp.net using c#. I want to give functionality of downloading a file. For dat i tried using SaveFileDialog in codebehind as under. SaveFileDialog DialogSave = new SaveFileDialog(); if (DialogSave.ShowDialog() == DialogResult.OK) { } else { } Bt wen comparing if condition, it gives me following error. "Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process." Can someone tell me the way to use this SaveFileDialog or some other way to achieve this functionality.
-
Hi... I am making a website in asp.net using c#. I want to give functionality of downloading a file. For dat i tried using SaveFileDialog in codebehind as under. SaveFileDialog DialogSave = new SaveFileDialog(); if (DialogSave.ShowDialog() == DialogResult.OK) { } else { } Bt wen comparing if condition, it gives me following error. "Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process." Can someone tell me the way to use this SaveFileDialog or some other way to achieve this functionality.
If you do this, you're trying to display the save file dialog on the server, not the client. Not going to work. If you send a file to a web browser, it will automatically try to give you the option to save it if it's not a recognised html file.
-
Hi... I am making a website in asp.net using c#. I want to give functionality of downloading a file. For dat i tried using SaveFileDialog in codebehind as under. SaveFileDialog DialogSave = new SaveFileDialog(); if (DialogSave.ShowDialog() == DialogResult.OK) { } else { } Bt wen comparing if condition, it gives me following error. "Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process." Can someone tell me the way to use this SaveFileDialog or some other way to achieve this functionality.
needhi_p wrote:
I want to give functionality of downloading a file
Just redirect to the file which you would like your users to download. Say you have a file in
files
directory. To download it,Response.Redirect("files/yourfilename.extension")
needhi_p wrote:
SaveFileDialog DialogSave = new SaveFileDialog(); if (DialogSave.ShowDialog() == DialogResult.OK) { } else { }
You are lost completly. Take some good books on ASP.NET and learn how it works.
SaveFileDialog
is commonly used in stand-alone applications not in ASP.NET.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
Hi... I am making a website in asp.net using c#. I want to give functionality of downloading a file. For dat i tried using SaveFileDialog in codebehind as under. SaveFileDialog DialogSave = new SaveFileDialog(); if (DialogSave.ShowDialog() == DialogResult.OK) { } else { } Bt wen comparing if condition, it gives me following error. "Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process." Can someone tell me the way to use this SaveFileDialog or some other way to achieve this functionality.