У меня есть веб-приложение ASP.NET, и я должен поместить данные от веб-страницы до файла синтезируемого текста. Я хотел бы дать пользователю способность выбрать папку, где файл будет сохранен. Например, когда пользователь нажимает на кнопку 'Browse', избранное диалоговое окно папки должно появиться.
Действительно ли возможно реализовать такую вещь в веб-приложении asp.net?
Спасибо,
Sergey
РЕДАКТИРОВАТЬ:
Глядя на ваш комментарий, я думаю, вы вместо этого имеете в виду отправку в поток ответов?
protected void lnbDownloadFile_Click(object sender, EventArgs e)
{
String YourFilepath;
System.IO.FileInfo file =
new System.IO.FileInfo(YourFilepath); // full file path on disk
Response.ClearContent(); // neded to clear previous (if any) written content
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "text/plain";
Response.TransmitFile(file.FullName);
Response.End();
}
Это должно отобразить диалоговое окно в браузере, позволяющее пользователю выбрать, где сохранить файл.
Вы хотите использовать элемент управления FileUpload
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.aspx
protected void UploadButton_Click(object sender, EventArgs e)
{
// Specify the path on the server to
// save the uploaded file to.
String savePath = @"c:\temp\uploads\";
// Before attempting to perform operations
// on the file, verify that the FileUpload
// control contains a file.
if (FileUpload1.HasFile)
{
// Get the name of the file to upload.
String fileName = FileUpload1.FileName;
// Append the name of the file to upload to the path.
savePath += fileName;
// Call the SaveAs method to save the
// uploaded file to the specified path.
// This example does not perform all
// the necessary error checking.
// If a file with the same name
// already exists in the specified path,
// the uploaded file overwrites it.
FileUpload1.SaveAs(savePath);
// Notify the user of the name of the file
// was saved under.
UploadStatusLabel.Text = "Your file was saved as " + fileName;
}
else
{
// Notify the user that a file was not uploaded.
UploadStatusLabel.Text = "You did not specify a file to upload.";
}
}
Такой диалог загрузки зависит от браузера.
Взгляните на общие обработчики с Response.Write или, еще лучше, напишите обработчик Http для этой цели.
Используя , пользователь может просматривать только файлы на своем компьютере. Он никак не сможет увидеть папки на сервере, если только вы не предоставите ему список или древовидную структуру, из которой он сможет выбирать. Вот пример построения такой древовидной структуры.