Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-11-19
3
Medium Priority
?
2,353 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Running classic asp applications under Windows Server 2008 R2 (x64) and IIS 7 is not as easy as one may think. It took me a while to figure it out while getting error 8002801d a few times. After you install the OS you will need to install the fol…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

715 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