-4

I have a website running on a server which is located on a place far far away. The website running is in ASP.net with C#. People log in to this website daily.

Now I would like, when a logged-in person clicks on a specific button, create a folder on that person's actual desktop, with some irrelevant things in that folder.

When I use Environment.GetFolderPath(Environment.SpecialFolder.Desktop) and I run the program locally, it works. But when I run it from the server, the folder does not appear on my computer.

DonBoitnott
  • 10,787
  • 6
  • 49
  • 68
Brewsli
  • 127
  • 1
  • 10
  • 12
    Imagine for a second the chaos that would ensue if any random website you visited could freely create files or folders on your desktop. – Damien_The_Unbeliever May 09 '18 at 11:46
  • Possible duplicate of [How to use Server.MapPath to get location outside website folder in ASP.NET](https://stackoverflow.com/questions/3422270/how-to-use-server-mappath-to-get-location-outside-website-folder-in-asp-net) – Surenthar Pitchai May 09 '18 at 11:50
  • @SurentharP No, that's completely different. Did you read the question? – mason May 09 '18 at 12:28
  • 1
    Think for a moment: have you ever just seen a website just create folders/files on your computer at its discretion? No, you have not. You may have been given the option to download a file to your PC, or to download a program that you then run which then can download more files. – mason May 09 '18 at 12:29
  • Mason, thats completely true. How do i do that then? How do i give someone the opportunity to save for example an xmlfile in THEIR computer? – Brewsli May 09 '18 at 12:39
  • @Brewsli https://stackoverflow.com/questions/2057836/how-can-i-return-a-pdf-from-a-web-request-in-asp-net / https://stackoverflow.com/questions/2169433/how-to-properly-serve-a-pdf-file (the same principle will apply for all files you want them to download - not just pdf) – mjwills May 09 '18 at 12:51
  • Did that help @Brewsli? – mjwills May 10 '18 at 04:32
  • @mjwills i havent been able to try it yet. But it looks really nice. I Will get back to you when i tried it. Thank you bro! – Brewsli May 10 '18 at 04:56
  • @mjwills thanks alot! I posted an answer on how i solved it. Thanks again! – Brewsli May 14 '18 at 08:28

1 Answers1

1

I solved it like this @mjwills and everyone else.

MemoryStream ms = new MemoryStream();
xml.Save(ms);
byte[] bytes = ms.ToArray();

Response.Clear();
Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}.xml", filename));
Response.ContentType = "text/xml";
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
Brewsli
  • 127
  • 1
  • 10