2

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

Sreedhar Danturthi
  • 7,119
  • 19
  • 68
  • 111

2 Answers2

2

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!

Off The Gold
  • 1,228
  • 15
  • 28
Muhammad Akhtar
  • 51,913
  • 37
  • 138
  • 191
  • @Muhammad I don't want to upload a file. I just want to get the file path and size of the file that i select in the folder. I don't know how to do that. Can you please help me with that ? Thanks in anticipation – Sreedhar Danturthi May 01 '11 at 12:16
  • 1
    @user653622 without file uploader control u cant do that – Govind Malviya May 01 '11 at 12:20
  • @Govind i got it !! Thanks for the advice though !! – Sreedhar Danturthi May 01 '11 at 12:24
  • 1
    There is one way if you really want to show Button to user, You can put Button control on Fileupload Control (Handle this in HTML), You have to handle manually using Javascript. I did this in one project, But I don't have code right now. That's in my office. – Muhammad Akhtar May 01 '11 at 12:24
  • If you need I will email to you tomorrow. You have to provide me your email. – Muhammad Akhtar May 01 '11 at 12:26
  • @Muhammad ok i will go with file upload control. How can i get the filesize and filepath after i upload the file ? – Sreedhar Danturthi May 01 '11 at 12:27
  • FileUpload1.FileContent.Length //File Size FileUpload1.FileName // – Muhammad Akhtar May 01 '11 at 12:31
  • @Muhammad i was telling to user653622. i know this trick I have code also in this take both button and file uploader in two div , set position absolute of both , set opacity of uploader to zero , set z index more then button of uploader when user click on button but actually click will perform on fileuploader . – Govind Malviya May 01 '11 at 12:34
  • @Muhammad I'm not getting the full path of the file that i'm upload i'm only getting the file name thats it. I want to get the full path, to be more specific like this : C:\Users\admin\Desktop\Software_Components\file_Name.exe . How can i get the full path ? – Sreedhar Danturthi May 01 '11 at 13:00
  • sure, I will send you code tomorrow. You don't need to know full path. As you must store at your end and I hope you don't want to track user path. – Muhammad Akhtar May 01 '11 at 13:23
2

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.

Kon
  • 27,113
  • 11
  • 60
  • 86