-3

i have a question, I have this code

    foreach (string line in File.ReadLines(**@"C:\fis32v6\fis32.ini"**))
    {
        if (line.Contains("TEST1"))
        {
            Label1.Text="TEST1";
            PdLine = "1";
        }
    }

    DataSet ds;
    ds = GetData(PdLine.ToString());

I want to read from txt file on client specific line with condition. When developing this and building the code it works, what ever i change in txt file can be read from my PC. But when I run the website on server it reads the txt file on that server instead of client I opened the website.

Is there any possibility to make the path relative?

Mrazik
  • 1
  • 1
  • 4
    The server cannot read text files on the user's computer directly. That would have huge security implications. However, it is possible to have the user upload the file and you can read it that way. – John Jun 28 '19 at 15:49
  • note: it is a closed network, so don't look at security.... maybe a different way to access it? like the web site needs to access it to get the variable and then use it in the function – Mrazik Jun 28 '19 at 15:54
  • 2
    There is no way, regardless of your thoughts about security. You cannot do that from server code. – Camilo Terevinto Jun 28 '19 at 16:00
  • @Mrazik If you want to transfer a file between a client and server, you'll need to make some kind of `http` or `ssh` request to the client from the server, or if this is a website, yo can have the user upload the file to the server though a standard file upload dialogue. There is plenty of information on any of these approaches. – Garrett Manley Jun 28 '19 at 16:03

1 Answers1

0

As John mentioned that would be a huge security issue, mostly to make sure the website doesn't dig around in your system. However it can be instigated from client side.

Just have search here on SO for 'upload file using asp.net' there are loads of hits with answers listed.

You didn't mention specific versions you use (MVC?, asp.net? / core?), and no context as to what workflow your code is running in (is it run on connection or during a specific process), is it configuration settings used for the web session itself? but it is possible to upload.

Should you require the file during startup that might be a bit trickier as you'd have to upload it somehow. If however it is settings for the web session, why not save it in a cookie?

Francois
  • 92
  • 9