views:

16

answers:

1

Hi,

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

A: 

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.

Oded
This is what I am doing. I have: <input type="file" id="faFile" name="faFile" runat="server"/> So how can the user upload the file so the application would be able to read it?
Greg
@grishaoks - Why are you not using the asp.net [`FileUpload`](http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.aspx) control? It gives you direct access to the uploaded byte stream.
Oded
Yep that works now :) Thanks!
Greg