Solved

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

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now