---
title: "Write to the file system in a directory"  
description: "Write to the file system in a directory"  
author: "Anonymous User"  
published: 2013-10-07  
updated: 2013-10-08  
canonical: https://www.mindstick.com/forum/1650/write-to-the-file-system-in-a-directory  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Write to the file system in a directory

I would like to write to the [file system](https://www.mindstick.com/forum/157850/what-is-a-file-system-explain-it-s-used-in-system-software) in a [directory](https://www.mindstick.com/forum/226/how-to-get-application-directory-using-c-sharp-csharp) C: \ directory [name](https://yourviews.mindstick.com/view/87450/how-to-generate-a-brand-name-using-linkedin-comprehensive-guide), for the moment I have this [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):

```
if (! System.IO.File.Exists (HttpContext.Current.Server.MapPath (filename)))
{
   TXTFile = new System.IO.StreamWriter (HttpContext.Current.Server.MapPath (filename));
}
else
{
   TXTFile = System.IO.File.AppendText (HttpContext.Current.Server.MapPath (filename));
}
```

\

but in this way writes on the [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) folder. How to [fix](https://yourviews.mindstick.com/view/80763/donald-trump-ki-jeet-fix-hai) it?

## Replies

### Reply by Manoj Bhatt

You can do:

Path.Combine(@"C:\", filename)

instead of

HttpContext.Current.Server.MapPath (filename)

Ensure your application has write access to the destination.


---

Original Source: https://www.mindstick.com/forum/1650/write-to-the-file-system-in-a-directory

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
