Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
if (excelfile.FileName.EndsWith("xls") || excelfile.FileName.EndsWith("xlsx"))
               {

                   Excel.Application application = null;
                   Excel.Workbook workbook = null;
                   Excel.Worksheet worksheet = null;
                   Excel.Range range = null;

                   string path = Server.MapPath("/Upload/" + excelfile.FileName);

Error coming from above statement  here with Internet Explorer.
Its working fine with Chrome 

An exception of type 'System.NotSupportedException' occurred in mscorlib.dll but was not handled in user code. The given path's format is not supported.

C#
if (System.IO.File.Exists(path))
                        System.IO.File.Delete(path);
                    excelfile.SaveAs(path);


What I have tried:

string path= System.IO.Path.GetFileName("/Upload/" + excelfile.FileName);
Posted
Comments
Member 12003400 14-Apr-16 5:03am    
please check file name that is getting generated for above. In chrome preceding with "file\\" formate is supported where not in another browser. Try to get if fetch using http or localhost.
kanna443 14-Apr-16 6:02am    
thanks.issue with file name only,I am getting full path in IE.So I trimmed the file name only by using below code

if (excelfile.FileName.EndsWith("xls") || excelfile.FileName.EndsWith("xlsx"))
{

Excel.Application application = null;
Excel.Workbook workbook = null;
Excel.Worksheet worksheet = null;
Excel.Range range = null;

string[] val = excelfile.FileName.Split('\\');
string FileName = val[val.Length - 1];

string path = Server.MapPath("/Upload/" + FileName);
if (System.IO.File.Exists(path))
System.IO.File.Delete(path);
excelfile.SaveAs(path);

}
Richard Deeming 14-Apr-16 9:09am    
It would be better to use System.IO.Path.GetFileName to extract the file name.
kanna443 16-Apr-16 1:32am    
Yes.Thanks

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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