Bonjour,
Je voudrais uploader des fichiers depuis une page asp.net. Après quelque recherche, j'ai trouvé ceci :
Le chemin est construit en fonction de certains paramètres, l'utilisateur choisie une catégorie (ex : internet) à partir d'une liste (c'est la drowdownlist1). Ce code ne fonctionne pas, j'ai toujours le message "impossible d'accéder au répertoire". La création du répertoire ne fonctionne pas et même quand il existe, un message d'erreur m'indique qu'il est inaccéssible. J'ai pourtant crée un repertoire accéssible en écriture.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 if (FileUpload1.HasFile) try { string strPath = "c:/tmp/"+DropDownList1.SelectedItem+"/"; DirectoryInfo di = new DirectoryInfo(strPath); if (di.Exists) { FileUpload1.SaveAs(strPath); Label1.Text = "File name: " + FileUpload1.PostedFile.FileName + "<br>" + FileUpload1.PostedFile.ContentLength + " kb<br>" + "Content type: " + FileUpload1.PostedFile.ContentType; Label1.Text = "Fichier correctement enregistré sous <b>" + strPath + "</b>."; } else { DirectoryInfo repertoire = Directory.CreateDirectory(strPath); FileUpload1.SaveAs(strPath); Label1.Text = "Création du repertoire "+DropDownList1.SelectedItem+" et enregistrement sous <b>" + strPath + "</b>."; } } catch (Exception ex) { Label1.Text = "ERROR: " + ex.Message.ToString(); } else { Label1.Text = "You have not specified a file."; } }
Une petite aide ?
Partager