Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Geeting Error: 'c:\windows\system32\inetsrv\DMS.xls' is denied

Posted on 2010-11-19
3
Medium Priority
?
2,403 Views
Last Modified: 2012-05-10
Hi, below is the code for writing to excel file from text box:

protected void Button1_Click(object sender, EventArgs e)
        {
            TextWriter tw = new StreamWriter("DMS.xls");
            tw.WriteLine(TextBox1.Text);
            tw.Close();
        }

When programme is run via INETMGR, below error is getting:

Access to the path 'c:\windows\system32\inetsrv\DMS.xls' is denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access to the path 'c:\windows\system32\inetsrv\DMS.xls' is denied.

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

Source Error:

Line 22:         protected void Button1_Click(object sender, EventArgs e)
Line 23:         {
Line 24:             TextWriter tw = new StreamWriter("DMS.xls");
Line 25:             tw.WriteLine(TextBox1.Text);
Line 26:             tw.Close();

I also provide access to ASPNET accounts on windows folder. But still getting same error.
Kindly help.
0
Comment
Question by:prdeshpande
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 34171349
Normally you wouldn't write to the inetsrv directory from a web app. It's just defaulting to the because you haven't specified a path when creating the TextWriter.

Try using the following to write to a path under your site:
    string path = Server.MapPath("~/DMS.xls");
    TextWriter tw = new StreamWriter(path);
    tw.WriteLine(TextBox1.Text);
    tw.Close();

Open in new window

0
 
LVL 1

Author Comment

by:prdeshpande
ID: 34171839
Thanks a lot, it’s working.
But I want to specify my own path like file should be stored in “E:/Report”, Report is a folder in E drive.
What should I do?
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 2000 total points
ID: 34171895
Instead of:
string path = Server.MapPath("~/DMS.xls");

Open in new window

You would use:
string path = @"E:\Report\DMS.xls");

Open in new window

It's only if you don't specify a path (i.e only the filename) that you run into problems. Otherwise you can use an absolute path or a relative path.
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question