I need to read content of a text file in client machine, I am using below code:
using (System.IO.StreamReader myFile = new System.IO.StreamReader(@"c:\\weight.txt"))
{
string myString = myFile.ReadToEnd();
}
It searches for file in server instead of client, is there any other way to read text.
Regards,
Bala
I'm sorry but no. The code is running on the server machine and does not have access to the client machine. If it did, imagine how vunerable we would be everytime we viewed a web page.
You could have the user upload a file then read it.
You have to provide a file upload control for the user to upload the file to the server. You can then edit it from there. Google how to upload files in asp.net and you'll find lots of examples.
The web browser cannot access the client machine drives or files.
You can upload the file to the web server and process the file.
Hi,
rbmbala
It searches for file in server instead of client, is there any other way to read text.
Yes. It's sever side code and it is supposed to read server side file.
As suggested by other members it cannot be done because of the abvious security reason.
Use FileUpload. Let the users upload there files to server then you may read the file. It is NOT possible to access the FileSystem of the user directly.
Refer to the following article:
Upload, Read, and Parse file in ASP.NET
Hope it helps!
Best Regards!
rbmbala
It searches for file in server instead of client
That's because C# code runs on the server.
rbmbala
is there any other way to read text.
You can use HTML5 File API for that. Below link show some examples
http://blog.teamtreehouse.com/reading-files-using-the-html5-filereader-api
In IE, it will support only version 10 and 11.
沒有留言:
張貼留言