Pergunta

I want following type of functionality

There are two users A and B both are visiting same page
This page has a button(Send File) .
When A clicks on button an Open Dialog box should appear
When A selects a file from Open Dialog box then there should be a link appear on B’s page containing file name
When B clicks on link, a SaveAs dialog should appear and after giving name and path file download should start.

Any kind of help in this context will be appreciated !

Foi útil?

Solução

The open dialog is acheived with the html input: <input type="file">

The save as dialog is acheived with the html anchor: <a href="www.myserver.com/download.aspx?filename='the file'">

After user A selects a file, you either use AJAX or the form onsubmit to upload the file via an upload.aspx page that you create.

On user B's machine, you use AJAX to call an updatefilelist.aspx page which returns the list of files available. Once user A's new file has been uploaded and saved on the server, the next ping from user B's AJAX call to updatefilelist.aspx will update the list shown on his screen to include the new file.

Clicking on the file calls the download.aspx page with the desired filename - you need to set Response.ContentType and Response.AddHeader("Content-Disposition", "attachment:filename=""" & IO.Path.GetFileName(Request.QueryString("filename")) & """") here. The save as dialog will then automatically pop up.

Outras dicas

Well the page could be split into two halves: one with the file uploading controls and the other that polls every 3-4 seconds via AJAX to see if there's new files.

Side "A" has a standard file upload control and uses the standard .NET way of saving uploaded files (see FileUpload.PostedFile.SaveAs(path), easy stuff). After the file upload is done, refresh this page.

Side "B" is a div that gets its contents from an AJAX call, XML, JSON or just plain ol' text. Have an AJAX page called "link.aspx" that kicks back the content in whatever format you want.

For the links, if you want to force the "download" window, then either the files need to be a type that isn't displayed normally in the browser, or you need to use another aspx page to serve out the file and force a dialog to Save or Open.

That aspx page will be called something like "file.aspx" and you could pass in a querystring param ("id" or something) to tell it what file you want. Your code behind of this page will figure out what file you need from that querystring param, then will serve out the file:

Response.AddHeader("Content-Disposition", "attachment; filename=" + file.fileName);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "image/jpeg"; // you gotta figure out the content type of the file here though. This is just the one for JPEGS.

byte[] buffer = new byte[file.Length];
dl.Read(buffer, 0, (int)file.Length);

Response.BinaryWrite(buffer);
Response.End();
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top