© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•15mo ago•
8 replies
electronic heartbreak.

Is it possible to create a file outside the project folder?

A yes/no question basically.

This is the code I currently use to create and store files.

When the
StoragePath
StoragePath
is "uploads", it creates an
upload
upload
directory within my
project folder
project folder
.

var savePath = Path.Combine(StoragePath, "test.png");
string directory = Path.GetDirectoryName(savePath);
if (!Directory.Exists(directory))
{
    Directory.CreateDirectory(directory);
}

using (var fileStream = new FileStream(savePath, FileMode.Create))
{
    await myObject.Image.CopyToAsync(fileStream);
}
var savePath = Path.Combine(StoragePath, "test.png");
string directory = Path.GetDirectoryName(savePath);
if (!Directory.Exists(directory))
{
    Directory.CreateDirectory(directory);
}

using (var fileStream = new FileStream(savePath, FileMode.Create))
{
    await myObject.Image.CopyToAsync(fileStream);
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ How to create a folder in project root?
C#CC# / help
2y ago
❔ Create new project in folder
C#CC# / help
3y ago
❔ Is it possible to use variables from file a in file b?
C#CC# / help
3y ago