tags:

views:

32

answers:

2

Hi Everyone,

The problem that I am having is on when I compile and run locally it works fine (i.e this "file.FileName" give me the file with the file name with path) but when I run the same code with the local IIS it doesnt work (i.e this "file.FileName" only give me the file name). can anyone please tell me whats going on.

        foreach (string inputTagName in Request.Files)
        {
            HttpPostedFileBase file = Request.Files[inputTagName];
            //File file; 
            if (file.ContentLength > 0)
            {
                string FilePath = file.FileName;
                ..........
            }
            ........
        }
A: 

MSDN says:

When overridden in a derived class, gets the fully qualified name of the file on the client.

If you want to save the file, following might help, inside the if check.

var filename = Path.Combine(Request.MapPath("~/App_Data"), Path.GetFileName(file.FileName));
file.SaveAs(filename);
KMan
A: 

When you say locally, I assume you are running the application directly from VS IDE. You have not mentioned which version of VS IDE you are using, whether its VS 2005 / 2008 / 2010. I also assume that you would be using one of these development environment.

If that is the case, when you run locally, VS will be using the inbuilt cassini server to access the filesystem. When you deploy the site it would be using the IIS. Because the cassini server runs under the same identity as VS it might be able to access the file.

When you try to do the same using IIS it might fail becuase it runs under the service account. You'll have to give the read 7 write permissions explicitely to the folder from where you are trying to read or write on the web server.

If you are using Windows 2008 server you'll need to check whether Network or network service account is being used to run the IIS process. For older operating systems it will be ASPNET account that will need permission to physical folder.

Nilesh Gule