Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Downloading File

Downloading File

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netcomdebugginghelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    needhi_p
    wrote on last edited by
    #1

    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.

    P N N 3 Replies Last reply
    0
    • N needhi_p

      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.

      P Offline
      P Offline
      Paddy Boyd
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • N needhi_p

        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.

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • N needhi_p

          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.

          N Offline
          N Offline
          needhi_p
          wrote on last edited by
          #4

          thnx everyone for helping.. have solved it

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups