Click here to Skip to main content
15,893,190 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
let me brief the problem i am trying to import the excel sheet from user and storing that in the godaddy folder of my domain where i have created a folder and given path of same in code behind but when i try to do this its showing me this error...
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: The SaveAs method is configured to require a rooted path, and the path 'http://brainlines.in/starsforum.org/Forum/Excel Sheets_Individuals/Indvisual.xlsx' is not rooted.

Source Error:


Line 25:
Line 26: string DuplicateEtry = "These Records are Already Present..!";
Line 27: FileUpload1.SaveAs(excelPath);
Line 28:
Line 29: string conString = string.Empty;

this is my code

C#
//Upload and save the file
            string excelPath = Server.MapPath("http://doamin_name/Forum/Excel Sheets_Individuals/") + Path.GetFileName(FileUpload1.PostedFile.FileName);
            string DuplicateEtry = "These Records are Already Present..!";
            FileUpload1.SaveAs(excelPath);

            string conString = string.Empty;
            string extension = Path.GetExtension(FileUpload1.PostedFile.FileName);


This code was working fine on local host it was saving excelsheet data to the database and save that excell file to the folder on my laptop but when i try to do same it showed me this error..where m going wrong please correct me and guide me for same for fixing this.
Posted
Updated 4-Sep-15 2:35am
v2

The string in MapPath needs to be relative to your site soot

string excelPath = Server.MapPath("~/Forum/Excel Sheets_Individuals/") + Path.GetFileName(FileUpload1.PostedFile.FileName);


that will store the file in the

yourdomain.com/Forum/Excel Sheets_Individuals

folder
 
Share this answer
 
Comments
hypermellow 4-Sep-15 4:12am    
Pipped to the post - 5'd!
Member 11932995 7-Sep-15 1:17am    
thanks for solution but i tried it edited code accordingly and uploaded on domain but its still showing this error now
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path '....\Forum\Files\Indvisual.xlsx'.

m sorry may be this is very common mistake but as m novice here so could not understand these small things please correct me to fix this issue
F-ES Sitecore 7-Sep-15 4:21am    
MapPath gives you an absolute path in the format c:\folder\file, so the fact that you have "..." in the path makes me think you're not using the code correctly.
Hi,

This line doesn't look right:
C#
string excelPath = Server.MapPath("http://brainlines.in/starsforum.org/Forum/Excel Sheets_Individuals/") + Path.GetFileName(FileUpload1.PostedFile.FileName);


If you have a look at the documentation for the Server.MapPath Method[^], you will see examples of it's correct usage.

I would expect the following to be closer to what you want:
C#
string excelPath = Server.MapPath(string.Concat("/Forum/Excel Sheets_Individuals/",FileUpload1.PostedFile.FileName));


... hope it helps.
 
Share this answer
 
its still not working...........:( how to fix this please tell me....
 
Share this answer
 

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