Solved

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

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
We need to disable default website IIS6 and7 3 20
Technology Resume 7 68
How do I hide MVVM menu items in WPF/XAML? 1 33
Unlocking a column in excel using C# 17 27
Lync server 2013 or Skype for business Backup Service Error ID 4049 – After File Share Migration
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 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