Salut,
J'ajoute mon fichier dans un dossier spécifié dans mon web.config grace au composant fileUpload
Code :
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 :
if(Directory.Exists(path))
{
char[] wordSeparators = newchar[]{',', ';', '!', '?', '+', '\\'};
char[] wordSeparatorsBis = newchar[]{',', ';', '!', '?', '+', '.'};
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);
}
}
}
}
}
}
}
publicstring 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
Afficher la suite