Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
Hi The below link is the code of uploading excel record to mssql server.


http://www.codeproject.com/script/Membership/View.aspx?mid=5170372[^]

Here the excel file which is to be upload are to be saved in the program folder.

I need a small alteration , that to give a choice to the user to choose the file from their location using FILEUPLOADER.

So how can i combine File uploader with this code.

The code as been ontained from code project by Mr Vivekananda..

Please help me out , its my project

Ankit
ankitjpk@gmail.com
Posted
Comments
joshrduncan2012 27-Sep-13 17:55pm    
Please do not post your email address on here unless you are willing to accept a LOAD of spam email. If someone replies to you, you'll get an email saying there is a new comment ready for you on here.

1 solution

To use File Upload Control you need 2 things:
1. The File Upload control itself (that's obvious).
2. A button control to trigger the file upload.

so you'll have let's say:
ASP.NET
<asp:fileupload id="fileupload1" runat="server" xmlns:asp="#unknown" />

and also a button right next to it:
ASP.NET
<asp:button id="btnUpload" text="upload" runat="server" xmlns:asp="#unknown" />


You'll need to add a "On Click" event to the button to actually take the file being posted.
Let's asume you already did that, and C# already has an on click event. Then you'll have to write something like

C#
string FileToSave = fileupload1.FileName;
fileupload1.SaveAs(Server.MapPath("~/") + FileToSave);



I recommend you to create an additional folder to your project to store files uploaded.
Also, include an additional if statement to your c# in case someone tries to upload a file with the same name so you don't get an error as in...


C#
if (File.Exists(Server.MapPath("~/") + FileToSave))
{
      ...save as another name
}


Additional caution would be to make sure the FileUploader has a file. Boolean property fileupload1.HasFile can be used for that.

You can also create a new name for the file using Math.Rand() or something.
 
Share this answer
 
v2
Comments
Homero Rivera 28-Sep-13 17:31pm    
If answer is good, please accept as solution, otherwise please tell.
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900