Link to home
Start Free TrialLog in
Avatar of Hojoformo
Hojoformo

asked on

File Upload & Read Problem - Could not find a part of the path

This should be a problem bug to find.  I keep getting error message "Could not find a part of the path "C:\Inetpub\wwwroot\WebApplication7\055070021FEB-04DET.csv" when trying to read records.   This is not the path I saved the file to on the server.  

string sFileDir= "c:/hosting/webhost4life/member/vcn770/ASPX/";
string sFileName = System.IO.Path.GetFileName(filUpload.PostedFile.FileName);
                        
filUpload.PostedFile.SaveAs(sFileDir + sFileName);
                        
StreamReader reader = new StreamReader(filUpload.PostedFile.FileName);  ???? is there something wrong with this code?????  
readcontents = reader.ReadLine();
ASKER CERTIFIED SOLUTION
Avatar of 2266180
2266180
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bob Learned
You might want to create a virtual directory, and get the path this way:

string root = Server.MapPath("virtual folder");

Bob
Avatar of jk_vr
jk_vr

Hello,
It seems u want to read the saved file itself....Pls try this

filUpload.PostedFile.SaveAs(sFileDir + sFileName);
                   
StreamReader reader = new StreamReader(sFileDir + sFileName);
Not sure - but worth a try...
Can you change this path lto have back slashes and try - )

cheers