0

I want users to be able to save files to a certain location so I need to save the folder path they want. I want to do something like the way to change the download location in Google Chrome:

enter image description here

I know to save a file I could use <asp:FileUpload runat="server" ID="file" /> But I just need to capture the path of the folder, not save a file. How do I do this in asp.net? Then later when I do save the file, I will have the location the file needs to go.

user123456789
  • 1,914
  • 7
  • 44
  • 100
  • umm I don't remember a control with that functionality but maybe you could create your own user control (try with a textbox, a file explorer/browser and a button) – luis_laurent Dec 08 '15 at 16:42
  • what type of control is that ? is that `FileUpload` or something else. if it is `FileUpload` you can do something like this `Server.MapPath(FileUpload1.FileName);` – Nad Dec 08 '15 at 17:15
  • @coder I don't want to save a file. I just want to save a folder location – user123456789 Dec 09 '15 at 09:22
  • 1
    It makes no sense to save a client folder location in a web application, as you have no access to that folder in any way. – CodeCaster Dec 09 '15 at 09:39
  • Think carefully about where your code is running. Chrome is running locally on a user machine with direct access to the file system. An ASP website runs on *your* server. It gets send data from the users local machine, but this is limited to the subset that the browsers are allowed to send based on security restrictions. In this context, it doesn't evne make sense to choose a download location - unless you are talking about a local app which can write files to that location, which your website can't. – xan Dec 09 '15 at 09:45
  • @CodeCaster I just want to get a folder location. So if I choose the documents folder on my computer, I want to save that path selected. – user123456789 Dec 09 '15 at 09:48
  • You cannot choose from serverside code where the file will be saved on the client. It works on your development machine because that machine is both server and client, so they share the same filesystem. After deployment on a real server, your code won't work anymore. – CodeCaster Dec 09 '15 at 09:49
  • @CodeCaster The file the user will save is saved on their local machine not on server. – user123456789 Dec 09 '15 at 09:50
  • 1
    Again, **you cannot control where files will be saved on the client**. It just is not how HTTP and browsers work. – CodeCaster Dec 09 '15 at 09:51

1 Answers1

-2

i think this would help you some first you need to import windows.forms to asp.net (aspx.cs) page.

using System.Windows.Forms;

then take a button and generate an event to it. use the code below it will show save as dialog box.

   SaveFileDialog my_Sfd1 = new SaveFileDialog();
        my_Sfd1.Filter = "All files (*.*)|*.*";    //here you can specify the file format.(*.*)indicates all files.
        my_Sfd1.Title = "Save file to";   //Title to display at top of the dialog box
        my_Sfd1.FilterIndex = 2;
        my_Sfd1.RestoreDirectory = true;
        if (DialogResult.OK == (new Invoker(my_Sfd1).Invoke()))
        {
                //add file here which you want to save.
        }
Sai Venkat
  • 7
  • 1
  • 5