T Rev
T Rev

Reputation:

Programmatically set name of file to upload in webpage

Is there a way to programmatically set the name of a file to be uploaded from a web page? I suspect that browser security restrictions make this impossible, but I'm hoping someone will prove me wrong.

I have a web application that needs to let the administrator upload HTML. The admin selects the HTML file, then the app uploads that file, plus figures out all the supporting files (images, stylesheet, etc) and uploads them too. There doesn't seem to be a way to programmatically upload the supporting files from a web page, since the user has to specify each file explicitly.

Currently I have a separate Windows app to do this, but it would be ideal to have this functionality integrated with the rest of the app. My back end is ASP.NET with C#.

Upvotes: 2

Views: 3828

Answers (4)

mrtnmgs
mrtnmgs

Reputation: 1552

Yes you can (in modern browsers)...

You can get and set the value of HTMLInputElement.files. See this answer.

Upvotes: 1

Brian
Brian

Reputation: 25834

You may be able to do this using some form of browser plug-in. This is more work for you (and there are potential security implications for this beyond those found when you just have users run your app). However, it may prevent a more integrated experience for your users. I'd hesitate to eliminate the application completely, though. Browser compatibility issues are common.

Upvotes: 0

Avitus
Avitus

Reputation: 15958

There is no way to programatically grab files from a user's computer via the browser. This would be a security violation if a website could just grab things.

Upvotes: 2

sangretu
sangretu

Reputation: 1208

No, you cannot do this without a client-side application or special plug-in.

Browser security doesn't allow the server to obtain information about the hard drive contents of the client.

Upvotes: 0

Related Questions