0

i'm on a task where I need to create a file serverside and move this file to an USB key.

Is it possible to copy a file from a webserver to an USB Key ? (any security issues)

Furthermore the user needs to indicate to which path the file needs to be saved on. Is there a control like the asp upload control, where the user can browse to the right directory or is the simple solution to use a textbox, where the user can write e.g. "E:\mygeneratedfiles"

The USB key is on the users local machines

user229044
  • 232,980
  • 40
  • 330
  • 338
Millerbean
  • 295
  • 2
  • 8
  • 17
  • Is the usb key on the local machine or on the server? – Wyatt Barnett Nov 15 '11 at 19:16
  • What machine is the USB key plugged into? The clients machine (i.e. the machine with the web browser) or the server (i.e. the machine that has IIS on it?) If the former, then this is not a programming question, you really can only give instructions to the user about how to use a browser. If the latter, then this is a question about how to write a file to the filesystem using ASP.NET – MatthewMartin Nov 15 '11 at 19:17
  • 1
    This question shows the various available technologies for writing directly to a users filesystem: http://stackoverflow.com/questions/292566/browser-application-local-file-system-access – MatthewMartin Nov 15 '11 at 20:24

2 Answers2

1

From the ASP.NET perspective, you can return the file in HTTP response, but once the file is sent to the client web browser, you're pretty much out of luck.

There might be something you can do with javascript to streamline the saving process (not my area of expertise), but accessing the client's filesystem directly, especially writing to it, is out of the question. If you want to do that you'll have to write an ActiveX control or similar type of plugin.

Edit:

For returning the file in the HTTP response, load your file in to a 1-dimensional byte array and use the following code pattern:

context.Response.Clear()
context.Response.AddHeader("content-disposition", "attachment;filename=" & objFile.FileName)
context.Response.BinaryWrite(objFile.FileImage)
context.Response.End()

In this example objFile.FileName is the file name string and objFile.FileImage is a Byte array containing the file. context is the current HttpContext.

pseudocoder
  • 4,314
  • 2
  • 25
  • 40
  • is it possible to only show "save" and "cancel" in the download box – Millerbean Nov 15 '11 at 20:44
  • @user816178 Not that I am aware of. Again, this is a function of the browser and such things are protected from the web server for security reasons. Some browsers don't even show a dialog, for instance Chrome by default saves the file in your default download directory, unless it is an executable file, in which a "save/discard" button panel is shown on the download bar. – pseudocoder Nov 15 '11 at 21:11
  • As noted by MatthewMartin in the comments, there are ways to access the client system through your web application, but they all involve a plugin of some sort which the user will have to accept for security reasons. – pseudocoder Nov 15 '11 at 21:14
0

Use this Code samples on this FileUpload control page

Siva Charan
  • 17,940
  • 9
  • 60
  • 95