EDIT:
En regardant votre commentaire, je pense que vous voulez dire pousser le flux de réponse à la place?
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();
}
Ceci devrait afficher une boîte de dialogue dans le navigateur permettant à l'utilisateur de sélectionner où enregistrer le fichier.
Vous voulez utiliser le contrôle FileUpload
dialogue
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.";
}
}
pas sûr que j'ai besoin de contrôle FileUpload. Ce contrôle me donne la possibilité de télécharger des fichiers sur le serveur. ce dont j'ai besoin est de donner à un client la possibilité de sélectionner un dossier local sur sa machine et enregistrer le fichier dans ce dossier. Je n'ai pas besoin de télécharger le fichier sur le serveur. J'ai besoin d'enregistrer le fichier dans le dossier spécifié de la machine locale –
réponse éditée pour montrer comment pousser le fichier dans le flux de réponse. – hearn
merci pour la réponse! c'est ce dont j'avais besoin. Puis-je vous demander une chose de plus? Est-il possible d'afficher la boîte de dialogue 'Sélectionner un fichier' sans la première fenêtre 'Ouvrir ou Enregistrer le fichier'? –