Click here to Skip to main content
14,578,463 members
Rate this:
Please Sign up or sign in to 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>
                                     <asp:RegularExpressionValidator   
                                  id="FileUpLoadValidator" runat="server"   
                                  ErrorMessage="Upload Jpegs and Gifs only."   
                                  ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.xls|.xlsx)$"   
                                  ControlToValidate="FileUpload1">  
                                  </asp:RegularExpressionValidator> 

<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;
          }
      }
Posted
Updated 5-May-20 19:33pm
v2
Comments
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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[^]
   
Comments
phil.o 6-May-20 4:06am
   
5'd
BillWoodruff 6-May-20 17:48pm
   
+5

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100