Click here to Skip to main content
15,915,975 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
var oldFileTxt = Server.MapPath(@"txtp1.Text");
var newFileTxt = Server.MapPath(@"txtp2.Text"); i have used this code and getting error while reading the path of the file.


What I have tried:

instead of server.path i have used File.Readline but getting the same error .i want this to be dynamic .please suggest
Posted
Updated 13-Dec-18 0:13am
Comments
Richard MacCutchan 13-Dec-18 6:06am    
What is the actual path of that file?

1 solution

Assuming the file is in the root directory of your website - which is a poor idea - you need to prefix the filename with a "~" - if you don't it's assumed to be in the same folder as the page ASPX file:
string oldFileTxt = Server.MapPath(@"~/txtp1.Text");
A better idea is to create a folder specifically for files and use that:
string oldFileTxt = Server.MapPath(@"~/Uploads/txtp1.Text");
 
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