Solved

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

Posted on 2010-11-19
3
2,216 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 500 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 500 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

770 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