Click here to Skip to main content
15,349,767 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I Have a problem with my project ,

I have to upload file excel into server ,

but before upload file ,i want to recheck and validate the file using
eppplus ,
And i think i need to get the file path to validate it using epp,
how can i solve this ?

What I have tried:

This is my code ,

In my aspx file

 <dd style="text-align:left"> 
                                    <asp:fileupload id="FileUpload1" runat="server" width="90%" onchange="callme()"></asp:fileupload>
                                  id="FileUpLoadValidator" runat="server"   
                                  ErrorMessage="Upload Jpegs and Gifs only."   

<pre> <asp:Button ID="btncheck" OnClick="uploadfile"  runat="server" Text="Cancel" CssClass="btn btn-primary"/>

this in on aspx.cs

protected void uploadfile(object sender, EventArgs e)
          if (FileUpload1.HasFile)
              string path = Server.MapPath("~/");
              string a = FileUpload1.PostedFile.InputStream.ToString();
              string fileexcel = FileUpload1.PostedFile.FileName;
              txtSchedule.Text = FileUpload1.PostedFile.FileName;
              string Path = HttpContext.Current.Request.PhysicalApplicationPath + FileUpload1.FileName;
              label1.Text = fileexcel;
Updated 5-May-20 19:33pm
F-ES Sitecore 6-May-20 6:37am
Even if you could get the path (you can't) there is nothing you can do with it as your .net code runs on the server and has no access to the client file system.

1 solution

You can't; this is due to security/privacy concerns.

What you want to do is upload the file and save it to a "temp" location.
Then you do your validation routine, if it passes you then send it to the final location.

There's a pretty good answer on SO for this; so I am not going to reinvent the wheel.
c# - Validate Excel(Spreadsheet) File Using EPPlus - Stack Overflow[^]
phil.o 6-May-20 4:06am
BillWoodruff 6-May-20 17:48pm

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