Problem with filepath while reading to filestream
-
i have the path of a file in a string variable. i am reading that using the following code new FileStream(path, FileMode.Open, FileAccess.Read); it's working fine when i execute from local machine .when i upload it into server it is showing the error 'Could not find a part of the file.. Any one can help me......... Anu
-
i have the path of a file in a string variable. i am reading that using the following code new FileStream(path, FileMode.Open, FileAccess.Read); it's working fine when i execute from local machine .when i upload it into server it is showing the error 'Could not find a part of the file.. Any one can help me......... Anu
try this code
new FileStream(Server.MapPath(path), FileMode.Open, FileAccess.Read);
Best Regard Pathan---------------------------------------------------
-
try this code
new FileStream(Server.MapPath(path), FileMode.Open, FileAccess.Read);
Best Regard Pathan---------------------------------------------------
-
You can't read a file that doesn't exist. Put the file that you want to read on the server. Put the virtual path to the file in the
path
variable, and useServer.MapPath(path)
to get the physical path to the file.--- single minded; short sighted; long gone;
-
You can't read a file that doesn't exist. Put the file that you want to read on the server. Put the virtual path to the file in the
path
variable, and useServer.MapPath(path)
to get the physical path to the file.--- single minded; short sighted; long gone;
-
How can i put the file into the server using path. if i am using file upload control then i can use fileuploadcontrolname.postedfile.saveas(server.mapath(filename)).but i am not using that control.i am only have the path of the file in a string variable...How can i do....... Anu
-
i have the path of a file in a string variable. i am reading that using the following code new FileStream(path, FileMode.Open, FileAccess.Read); it's working fine when i execute from local machine .when i upload it into server it is showing the error 'Could not find a part of the file.. Any one can help me......... Anu
Guffa was right and I just submit his answer with simple code
//fudoc is HtmlInuptFile //UplDoc is Folder inside project FileInfo fInfo = new FileInfo(fudoc.Value.ToString());//here get path of local machine fudoc.PostedFile.SaveAs(Server.MapPath("~/UplDoc/") + fInfo.Name);//here save file in folder which exists in project
after this read file from Folder UplDocFileInfo fi = new FileInfo(Server.MapPath("~/UplDoc/filename.extension"));
Hope it helped
I Love SQL
-
How can i put the file into the server using path. if i am using file upload control then i can use fileuploadcontrolname.postedfile.saveas(server.mapath(filename)).but i am not using that control.i am only have the path of the file in a string variable...How can i do....... Anu
You can't do that directly SO you want to read the Uploaded file then use fileuploadID.PostedFile.InputStream as input to Stream reader and read the file
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
Guffa was right and I just submit his answer with simple code
//fudoc is HtmlInuptFile //UplDoc is Folder inside project FileInfo fInfo = new FileInfo(fudoc.Value.ToString());//here get path of local machine fudoc.PostedFile.SaveAs(Server.MapPath("~/UplDoc/") + fInfo.Name);//here save file in folder which exists in project
after this read file from Folder UplDocFileInfo fi = new FileInfo(Server.MapPath("~/UplDoc/filename.extension"));
Hope it helped
I Love SQL
i think no need to save also give one of the steamreader parameter as uploadfileCntrolID.Postedfile.InputStream
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
i think no need to save also give one of the steamreader parameter as uploadfileCntrolID.Postedfile.InputStream
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
anujose wrote:
i didn't understand.can you give me a sample code?..
The example code will be exactly as Pathan showed:
new FileStream(Server.MapPath(path), FileMode.Open, FileAccess.Read);
The path in thepath
variable should be a virtual path, like for example"/SomeFolder/SomeFile.txt"
.--- single minded; short sighted; long gone;