locked
File Dialog in ASP.Net RRS feed

  • Question

  • User1016820894 posted

    I have an asp.net web application where I have a button that when clicked creates several reports and then merges them together into one pdf file using itextsharp.dll in c# code behind. Currently I have the folder destination hard-coded in the application. I need to update it so that when the user clicks on the button a file dialog box comes up that allows them to choose the folder they want to save the file to (just need to choose the folder, not select a file etc). I tried the Fileupload feature but that requires you to select a file. In windows forms I used OpenDialog but that doesn't seem to be available in a web application. What do I need to do to accomplish this task?

    Thanks.   

    Friday, April 19, 2019 1:14 PM

Answers

  • User-1174608757 posted

    Hi baldwinjohn,

    In asp.net ,we couldn't just directly get a folder by using anything like FileBrowserDialog.

    Since the desktop application is running on the user's local computer, FileDialog can directly manipulate the local folder and then read all the files in a folder through the file api. But the web application is different. It can't read the contents of the user folder through the file api because the code of the web application is running on the server side, it can only operate the folder of the server and cannot manipulate the files on the user's computer. folder.

    Else neither the HTML tag nor the javascrpt provides an API to manipulate a folder. The web page can only manipulate files and cannot manipulate folders.

    Best Regards

    Wei

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 23, 2019 3:16 AM

All replies

  • User-1174608757 posted

    Hi baldwinjohn,

    According to your description,I couldn't understand your requirement clearly.Do you want to update the folder in the server or you just want that when users enter the button,the folder could be downloaded  in users' local machine? In fact , fileupload control is used for submit folder from local side to server.It seems not suitable for your requirement.

    If you just want to use fileupload control to submit a folder, you could  save multiply files in folder as long as  you add attribution setting  in this control.You could see as below:

    in .net 4.5 and higher:

    <asp:FileUpload ID="fileImages" AllowMultiple="true" runat="server" />

    .NET 4 and below

     <asp:FileUpload ID="fileImages" Multiple="Multiple" runat="server" />

    Here is the link, I hope it could help you.

    https://stackoverflow.com/questions/17441925/how-to-choose-multiple-files-using-file-upload-control

    Best Regards

    Wei

    Monday, April 22, 2019 2:12 AM
  • User1016820894 posted

    I don't need to upload any files. Just choose a folder location. File upload forces you to choose an existing file. Is there a way to use FileBrowserDialog in asp.net?

    Monday, April 22, 2019 12:15 PM
  • User-1174608757 posted

    Hi baldwinjohn,

    In asp.net ,we couldn't just directly get a folder by using anything like FileBrowserDialog.

    Since the desktop application is running on the user's local computer, FileDialog can directly manipulate the local folder and then read all the files in a folder through the file api. But the web application is different. It can't read the contents of the user folder through the file api because the code of the web application is running on the server side, it can only operate the folder of the server and cannot manipulate the files on the user's computer. folder.

    Else neither the HTML tag nor the javascrpt provides an API to manipulate a folder. The web page can only manipulate files and cannot manipulate folders.

    Best Regards

    Wei

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 23, 2019 3:16 AM
  • User626783203 posted

    good answer

    Wednesday, June 5, 2019 3:46 PM
  • User2053451246 posted

    Is the document just opening instead of asking to save?  How the browser treats specific file types behave depends on the user's browser selections (always ask when downloading this type of file..., etc).  You can add

    Content-Dis; filename="MyPdf.pdf"

    to your download code but if the user has already told their browser to just open a specific file type you can't do anything about it.

    Wednesday, June 5, 2019 8:29 PM