Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8084347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:46:04+00:00 2026-06-05T17:46:04+00:00

I am using ASP.NET for my web application. I am able to write a

  • 0

I am using ASP.NET for my web application. I am able to write a text file in server path using this method Server.MapPath(). But I also want to create a text file in different location like C:\ or D:\. I am using IIS version 5.1.

This is my code to write a file in the C:\ drive.

    string text="Welcome";
    StreamWriter sw = new StreamWriter("C:\\sample.txt", true);
    sw.WriteLine(text);
    sw.Close();

When I run the application it throws a runtime exception saying

UnauthorizedAccessException. Access to Path C:\sample.txt is denied.

Please guide me how to write a text file in the C:\ drive…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:46:06+00:00Added an answer on June 5, 2026 at 5:46 pm

    Its obvious that you need permission to be able to create/write/delete etc a file on any location on disk.

    The tip here is that your asp.net application is running under one pool, and the pool is running under specific user – this user must have the correct permissions.

    Update

    There is two kind of users that “runs” together on an asp.net page. The one have to do with permission with IIS, and this is the one that KBoek speak about. For example, a user request a page , from IIS, and the IIS using the USER A to see if can read this file and send it back to web – or have permissions to run.

    The second type of user is the pool. From the moment that IIS have permissions to run the pool then run it using the pool user. So if the file is going to read by pool the pool must have permission to read and not the iis.

    Why there are two kind of users here. Because the one is represent the user that see the data, and the other represent the programming that we made.

    If for example we have an automation tool that make delete to a set of files, then we do not won to the remote client to direct access this file and maybe delete if he like to – but only we must have this permission to do only on programming. So our asp.net program have different permissions from the user that connect and see page, so we have two kind of users here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an asp.net web application written in C# using a SQL Server 2008
I maintain a legacy ASP.Net Web application (using .Net 2.0 + SQL Server 2005
I am building a Web Application using asp.net (C#). I come from windows forms
I am building a web application using ASP.NET MVC that has two very distinct
I'm developing a web application using ASP .NET MVC 1.0 and jQuery (including the
I have a web application where I am using asp.net tree view control to
I have a asp.net web application and I'm using cache (HttpRuntime.Cache) to save some
I'm using ASP.NET MVC to develop a web application, deploying to IIS 7. I've
I have an ASP.NET web application that is using forms authentication. Everything is configured
I have an ASP.NET web application the entire site is browsed over HTTPS using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.