This is a migrated thread and some comments may be shown as answers.

Select a .txt file and .xlsx file from local machine

4 Answers 92 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
: Arumuga Vignesh
Top achievements
Rank 1
: Arumuga Vignesh asked on 30 Jul 2013, 12:45 PM

Hi,

I have a requirement in my project to select a file from local machine

Scenario:

when a button is clicked, user should see a browser window to choose a file,
and user can select only one file, and user should be accessible to all the drives,desktop as in windows browser
and finally we need the selected file path with file name to manipulate that file.

Can you pls provide the code for this, I am working on this almost one week but unable get the solution

Regards,
Arumugam

4 Answers, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 31 Jul 2013, 09:32 AM
Hi Arumuga,

For this scenario you could use RadAsyncUpload control. It covers these requirements. Here is the code you can use:

ASPX:

<telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server" AllowedFileExtensions="txt,xlsx" HideFileInput="true"
OnFileUploaded="RadAsyncUpload1_FileUploaded"></telerik:RadAsyncUpload>
<telerik:RadButton ID="rbUpload" runat="server" Text="Upload"></telerik:RadButton>

CS:

protected void RadAsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
{
    string path = Server.MapPath("~/Uploads/");
    string fileName = e.File.FileName;
    e.File.SaveAs(path + fileName);
}

In the code above AllowedFileExtensions property allow you to specify which files types user can select. Other property HideFileInput displays control as a button. Finally uploaded file can be manipulated on the server in OnFileUploaded event.

Additional resources you may find for useful:

Regards,
Hristo Valyavicharski
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
: Arumuga Vignesh
Top achievements
Rank 1
answered on 31 Jul 2013, 12:54 PM
Hi I should have the browser option on one button click itself
And the file should not be uploaded ,i need only the path of the file to manipulate

Canyou pls help me
0
Shinu
Top achievements
Rank 2
answered on 02 Aug 2013, 09:05 AM
Hi Arumuga,

Unfortunately, the full path is no longer provided by the browsers due to a security reasons. This is the default behavior. Only IE6 and IE7 provide the full name along with the path and in all other browsers it is truncated to:

1) Only file name (Chrome/Safari)
2) C:\fakepath in IE/Opera
3) Full path displayed - FireFox, however, only filename is sent to the server.

Suppose you want to open the Open File browser dialog on a button click, you can display the Select button of the RadAsyncUpload alone and hide the textbox by setting the HideFileInput property of the control to true.

Thanks,
Shinu.
0
Hristo Valyavicharski
Telerik team
answered on 05 Aug 2013, 12:49 PM
Hi Arumuga,

Shinu is right, different browsers show very limited information. It is a security restriction.

Regards,
Hristo Valyavicharski
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
General Discussions
Asked by
: Arumuga Vignesh
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
: Arumuga Vignesh
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or