Yes From Visual Studio it will work fine but from Local host won't work. And here is the reason and solution.
When your application is running from Visual Studio, your application having sufficient privilege to write of your hard drive, hence your application is running fine as it is able to create file.
Now Come to the point when you are hosting it to IIS.
Application pool having 3 types of identity.
1. NetworkService<br />
2. Local Service<br />
3. Local System
"
Network Service
" is the default Identify. "
defaultappPool
" is also runs under the "
Network Service
" Identity
By default your application pool runs on "
NetworkService
" account which has very minimum access to your drive, only read. So, When your application trying to write a file on drive, its getting access denied.
The solution, is give the Application Pool with "
LocalSystem
" privilege or
Run your application pool with the account who have write access
on drive.
So, create a new Application Pool for your application, Change the Identity to "
LocalSystem
" or Run on High Privilege account.
To know more about "
Application Pool and the Identity
" Read this section from one of my article
Beginner's Guide : Exploring IIS 6.0 With ASP.NET [
^]
That will resolve your issue.
Cheers !!