browsing to a file on button click in asp.net - c#

I want to browse to folder on button click and select a file in that folder. When user selects a particular file. I want to retrieve the folder path and size of that file ?
How can i do that in asp.net with c#
BTW i'm using vs2008.
Please help me
Thanks in anticipation

Why not use the FileUpload control instead of a Button? http://asp.net-tutorials.com/controls/file-upload-control/
Using FileUpload control, it will accept file uploads from users and is extremely easy. With the FileUpload control, it can be done with a small amount of lines of code, as you will see in the following example. However, please notice that there are security concerns to to consider when accepting files from users!

Use the FileUpload control to let user browse to the file, select it and upload it. Unfortunately, there is no way to retrieve the file size until the file is uploaded (without using Silverlight or other third-party browser components). Once the file is uploaded, you can retrieve file size via the ContentLength property.

Related

how to upload a folder includes sub folders? [duplicate]

I need something like the FileUpload control in asp.net that will allow the user to browse for a folder and enter a file name of a new file to upload.
From what I've seen FileUpload requires a file to be selected. It seems that html input type="file" has the same requirement.
Thanks!
Selecting an entire folder is not possible in FileUploadControl as it is meant for a single file. Although you can have a Multi File Selection. Multiple File Upload User Control
C# has build-in FTPrequest class where you can create folders, upload files, delete files etc.
If you want to upload folders from a webpage, you cannot use this technology in the browser, then you will have to use a rich-client such as Java, Flash or similar plugin.
If you can provide the users with a Windows or Mac client, you can use C# (either .NET or Mono) for the FTP transfer.
ZIP files arent a problem for ASP.net nor C#, but you still only upload 1 file (zip-archive) and then its up to the server to unzip it using eg. C#. Look at 7-Zip which is opensource, then you might get some ideas too.
You could also just try and use the build-in lib for it (compression):
http://www.eggheadcafe.com/community/csharp/2/10050636/how-to-compress-and-decompress-file-in-c.aspx
or try this link...
http://www.aurigma.com/docs/iu7/uploading-folders-in-aspnet.htm

How do I Open a file directly(from the binary data saved in db), when I will click a link?

I am working on a file uploading functionality using ASP.NET, C# and telerik. I am using telerik:RadAsyncUpload control. I already convert the file to byte array and save in the SQLServer Database.
On update page, I need to open file directly(from the binary data saved in db), when I will click a link. I need to Open that file in separate browser tab/window. I do not want to save file Physically on any local drive while retrieving it.
Please help me out.
What I have tried?
For time been, I am saving that binary data in a blank file located at some local drive and then attaching it to that link. but I do not want to save file Physically on any local drive while retrieving it. I want .....when user will click link binary data will directly flush on separate browser tab and he can view the file.
Create a handler (arbitrary one or an aspx page, whatever you find easier) that will read the database (e.g., based on a querystring argument) and return the appropriate response (via the Response object, e.g., Response.BinaryWrite()).
Note that you should set the appropriate headers and that depending on the type of file you return the browser may prompt the user to open/save it instead of opening it inline. You have some control over that via the content-disposition HTTP header, but it is ultimately up to the browser.
Also, you may want to use a RadWindow to open that handler to keep browser popups to a minimum to reduce the risk of them getting blocked by the browser.

How do I open a PDF file List in a new Window in ASP.NET?

How do I open a PDF file List in dialog box in a new Window in an ASP.NET application ?
I want list of pdf file which is stored in folder in my application and then select any of pdf and save in logged user's particular folder.
Since you want to display a list of pdf files stored in a folder on the server side you will need to render the list to a page in some format that makes sense. You may open that up as a dialog (perhaps using something like jquery ui) but it wouldn't be necessary.
Next to each file you could have a button that indicates the action you are after, say 'Copy'.
This would then send the id/name of the relevant file to the server and the server code could copy the file to some other location on the server that you refer to as the users folder.
However, if you want to download the file to the user's machine that is something else and you will find many answer here on SO about that.

how to show file on asp.net form

how to get file on asp.net form so that user can download it?
suppose i have created one excel file and i want to upload it on form so that user can download it, fill the details when they are offline.
You can use
Response.AddHeader("content-disposition", "attachment; filename=test.txt");
Response.WriteFile(#"test.txt");
Response.End();
Otherwise if it's a specific file you can use a normal Download Meand point it to the files location.
Use the fileupload component. I would store the file locally on the server and then display a list of the uploaded files.the list would be a list of hyperlinkswhich you can link directly to the uploaded files so when the user clicks on one, the file download begins automatically using the standard browser behavior.
Place the file in one of your directories under the application root folder and then you can simply place an anchor tag to let user download the file, like
abc

How can I read an xml file from the users computer on an ASP.NET MVC2 site?

I am writing a website to consolidate a bunch of XML files with data into one MySQL database. I need to have a way to allow users to select a directory on their computer that contains a bunch of xml files. The site then reads each of those files and takes care of consolidating the information.
Is there a simple way (like the default open file dialog for win forms and wpf) to bring up a file dialog on a users computer, let the user pick a directory, and then be able to read the xml files in the selected directory? Would I have to upload them to the site temporarily first? Or could I just access them on the users computer?
Thanks!!
You can't access files from a webserver directly. You would need to write an ActiveX Control if you really don't find another way.
The standard conform way it just uploading one or more files with the browser fileupload:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.aspx
I would suggest that the user should zip the files and just upload the zip file.
There are some hacks - but I don't think it fits:
http://the-stickman.com/web-development/javascript/upload-multiple-files-with-a-single-file-element/
http://dotnetslackers.com/articles/aspnet/Upload_multiple_files_using_the_HtmlInputFile_control.aspx
I think you have to have a web dialog to upload the files to a temp location like you already mentioned and do the consolidation there before committing to your database. Or, maybe you can do the consolidation in JavaScript in the user's browser instance.

Categories