Question

I have a web application which I uploaded using IIS. I want the users using the application would be able to select a file located on their (the user) computer and read its contents.

The code is:

TextReader trs = new StreamReader(faFile.Value);
            DataAccessLayer.clearFA();
            string line = trs.ReadLine();
            // Read all unneeded data 
            while (line != "** Start Data **")
            {
                line = trs.ReadLine();
            }
            line = trs.ReadLine();
            while (line != null)
            {
                string[] words = line.Split('*');
                // There is no message
                if (words[4] == "")
                {
                    DataAccessLayer.insertIntoFA(Int32.Parse(words[1]), words[3].Replace("'", ""));
                }
                else
                {
                    DataAccessLayer.insertIntoFA(Int32.Parse(words[1]), words[4].Replace("'", ""));
                }
                line = trs.ReadLine();
            }         
        }

When I run it from my pc it works. But when I try to run it from the IIS it gives me the following error:

Could not find a part of the path 'C:\Documents and Settings\myUser\Desktop\file.txt'. 

I understand that the application cant read the file from the user pc. Any idea how can I make it work?

Thanks!

Greg

Was it helpful?

Solution

This is done for security reasons - a browser does not have access to the filesystem of the user.

There is no way to work around this, as all other technologies running inside a browser are sandboxed and limited (again, for security reasons).

The closest you can get is to use an <input type="file"> that lets the user to select a file for upload.

OTHER TIPS

The upload file's path in IE 8 is a full path. You can obtain filename from the full name. Combine server path and filename before saving file

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top