Hi
I want to save file in Application folder not in D:. How it can be done
C#
var pdf0 = DateTime.Now.ToString("yyyyMMddHHmm") + "_" +secondPart;
var request0 = new RestRequest(@"/" + secondPart, Method.GET);
var client0 = new RestClient(firstPart);
var content = client0.DownloadData(request0);
MemoryStream ms = new MemoryStream(content);
FileStream file = new FileStream(@"D:\" + pdf0 , FileMode.Create, FileAccess.Write);
ms.WriteTo(file);
file.Close();Thanks

Pasang TamangRank #449 · 5.6K reputationPosted Dec 27, 2022, 10:49 AM EST
Hi Ramco,
If you are using ASP.NET MVC to develop your application then you can use Server.MapPath. Below is the code example.
var filePath = $"{Server.MapPath("~/PDF")}\\{pdf0}.pdf";PDF is the foldername from my application folder root directory.
Regards,
Pasang
Pasang TamangRank #449 · 5.6K reputationPosted Dec 27, 2022, 10:57 AM EST
Hi Ramco,
You are developing web application or windows application? If you are using .NET Core then there will be bit different code structure. If you can give me idea about this then I can suggest you what exact code you will need.
Regards,
Pasang
Ramco RamcoRank #462 · 5.4K reputationPosted Dec 27, 2022, 11:44 AM EST
Hi
Web application using .net c#
Thanks
Pasang TamangRank #449 · 5.6K reputationPosted Dec 27, 2022, 11:47 AM EST
Hi Ramco,
And it is based on .NET Framework or .NET Core? Please try with the code example which I have shared in my previous reply.
Regards,
Pasang
Puneet KankarRank #446 · 5.6K reputationPosted Dec 27, 2022, 3:09 PM EST
Hi Ramco,
Please check below link and make the changes according to your folder.
https://www.c-sharpcorner.com/blogs/upload-and-save-file-to-other-drive-on-place-of-wwwroot-or-application-directory-in-asp-net1
https://www.aspsnippets.com/questions/451294/Save-file-in-Project-Folder-Directory-using-C-and-VBNet-in-Windows-Application/
John IwaszRank #811 · 2.8K reputationPosted Dec 28, 2022, 11:12 AM EST
FileStream file = new FileStream(Path.Combine(AppContext.BaseDirectory, pdf0) , FileMode.Create, FileAccess.Write);That should get you what you need for Console apps.
Ramco RamcoRank #462 · 5.4K reputationPosted Dec 27, 2022, 10:52 AM EST
Hi Pasang
I am using .net c#. What changes i need to do.
Thanks