Salut,

J'ajoute mon fichier dans un dossier spécifié dans mon web.config grace au composant fileUpload

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
if (fUpDocument.HasFile)
        {
            string path = TfeConfiguration.Path;
            path += "\\" + ddlProjet.SelectedItem.ToString();
            try
            {
                path += "\\" + Server.HtmlEncode(fUpDocument.FileName);
 
                fUpDocument.SaveAs(path);
 
            }
         }
J'affiche ensuite tous mes dossiers et fichiers dans un treeView

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
if (Directory.Exists(path))
            {
                char[] wordSeparators = new char[] { ',', ';', '!', '?', '+', '\\' };
                char[] wordSeparatorsBis = new char[] { ',', ';', '!', '?', '+', '.' };
                string[] files; // pour avoir les noms des fichiers et sous-répertoires 
                files = Directory.GetFileSystemEntries(path);
                int filecount = files.GetUpperBound(0) + 1;
                for (int i = 0; i < filecount; i++)
                {
                    string[] words = files[i].Split(wordSeparators,
                                StringSplitOptions.RemoveEmptyEntries);
                    TreeNode n = new TreeNode(files[i]);
 
                    string[] tab = {"gif", "jpeg", "pdf", "doc"};
                    n.Text = words[words.Count() - 1];
 
                    DirectoryInfo f = new DirectoryInfo(files[i]);
                    if (f.Parent.Parent.Parent != null)
                    {
                        n.ImageUrl = "~/icone/rep.jpg";
                        tVDocument.Nodes.Add(n);
                    }
                    else
                    {
                        n.ImageUrl = "~/icone/repRoot.jpg";
                        tVDocument.Nodes.Add(n);
 
                        path =  files[i];
                        string[] filesEnfant = Directory.GetFileSystemEntries(path);//récupère les fichiers des sous dossiers
                        if (filesEnfant.Count() > 0)
                        {
                            for (int j = 0; j < filesEnfant.Count(); j++)
                            {
 
                                string type = GetMIMEType(path);
                                //Type te = filesEnfant[j].GetType();
                                n = null;
                                //filesEnfant[j]
                                n = new TreeNode(filesEnfant[j]);
                                n.ImageUrl = "~/icone/" + type + ".gif";
                                n.SelectAction = TreeNodeSelectAction.Expand;
                                n.Text = words[words.Count() - 1];
                                tVDocument.Nodes[i].ChildNodes.Add(n);
                                //tVDocument.Nodes.Add(n);
                            }
                        }
 
                    }
                }
            }
 
       }
 
    }
    public string GetMIMEType(string path)
    {
        RegistryPermission regPerm = new RegistryPermission(RegistryPermissionAccess.Read, "\\HKEY_CLASSES_ROOT");
        RegistryKey classesRoot = Registry.ClassesRoot;
        FileInfo fi = new FileInfo(path);
        String dotExt = fi.Extension.ToLower();//aucune extension n'est trouvée
        RegistryKey typeKey = classesRoot.OpenSubKey(@"MIME\Database\Content Type");
        String Keyname = "";
        foreach (string keyname in typeKey.GetSubKeyNames())
        {
            RegistryKey curKey = classesRoot.OpenSubKey(@"MIME\Database\Content Type\" + keyname);
            string test = (String)curKey.GetValue("Extension");
            if ((String)curKey.GetValue("Extension") == dotExt)
            {
                Keyname = keyname;
            }
        }
        return Keyname;
 
    }
Voilà mon problème est que je ne récupère aucune extension pour le fichier et je ne vois pas du tout pourquoi.

Merci de votre aide