To achieve this, we can use the following namespace: "System.IO". Here is a custom code snippet, where the first parameter is the filePath, the second parameter is inputStream and the last parameter is fileName. filePath parameter will use for directory path where you want to save the file, inputStream will holds file stream and fileName will be your file name.
public static void SaveStreamAsFile(string filePath, Stream inputStream, string fileName) {
DirectoryInfo info = new DirectoryInfo(filePath);
if (!info.Exists) {
info.Create();
}
string path = Path.Combine(filePath, fileName);
using(FileStream outputFileStream = new FileStream(path, FileMode.Create)) {
inputStream.CopyTo(outputFileStream);
}
}
Here is a detailed tutorial: Working with DirectoryInfo In C#

Tahir AlviPosted Jan 25, 2022, 2:29 PM
Very nice and authentic piece of code. Great Faisal Bahi.
Roberto AndrésPosted Feb 2, 2021, 4:34 AM
What about XLSX Files, when i try to open them is not possible
Hamid KhanPosted Sep 4, 2019, 2:10 AM
Good example...………..