D B
D B

Reputation: 127

Open file on the desktop from ASP.NET and C#

I want a simple solution to open a file on desktop. Below is the file path that I would like to open. I don't want to use browse button to upload the file. I just want that file to load up as a textfile and be read.

"C:\Users\Donald\Desktop\ingredients.txt"

Upvotes: 0

Views: 1331

Answers (1)

TheNorthWes
TheNorthWes

Reputation: 2739

Whoops. Just realized you want to do this via ASP.Net aka through a web browser.

You cannot do that. Because this would be an enormous security risk if any old web page could reach in and grab files. HTML5 has dramatically improved file system access though. There are many questions, with good answers, on how to support drag and drop file upload etc. But your javascript should never be allowed to reach out and grab files, imagine if their desktop had supersecretPasswords,CreditCardNumbers,AndSocialSecurity.csv

You can use an applet if you really want, but be advised support for those is already be phased out. Source

C# has a constant for the desktop, assuming you know the name of the file... string desktopPath = Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory); File myFile = new File(desktopPath + "ingredients.txt");

Upvotes: 6

Related Questions