Ciao a tutti, tempo fa avevo trovato un esplora risorse carino... funziona tutto correttamente ma ho notato che quando apro un file (cliccando sul link del file) mi genera il file e, in fondo al file, trovo la pagina HTML dal <!DOCTYPE fino al </HTML>
((
Avevo provato a piazzare un
Response.End();
col risultato che mi vengono visualizzati tutti i caratteri del file nella pagina web!
codice:<%@ Page Language="C#" AutoEventWireup="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected String numero; // numero dell'ordine protected void Page_Load(object sender, EventArgs e) { numero = Request.QueryString["numero"].ToString(); lblMessage.Text = ""; if (Request["download"] == "true") { makeDownload(Request["fileToDownload"]); } if (!this.IsPostBack && !(Request["download"] == "true")) { TreeNode rootNode = fileTree.Nodes[0]; string initialDirectorty = @"Z:\Inetpub\wwwroot\DOC\pratiche\" + numero; //Server.MapPath("~"); populateNode(rootNode, initialDirectorty); } } private void populateNode(TreeNode rootNode, string directoryPath) { string[] files = System.IO.Directory.GetFiles(directoryPath); string fName = null; string dirName = null; foreach (string fNameCompete in files) { int sleshPosition = fNameCompete.LastIndexOf(@"\"); fName = fNameCompete.Substring(sleshPosition + 1); TreeNode fileNode = new TreeNode(fName, fNameCompete); fileNode.SelectAction = TreeNodeSelectAction.Select; fileNode.Expanded = true; fileNode.PopulateOnDemand = false; string downloadString = "?download=true&fileToDownload={0}&numero=" + numero; fileNode.NavigateUrl = this.Request.FilePath + string.Format(downloadString, Server.UrlEncode(fileNode.Value)); rootNode.ChildNodes.Add(fileNode); } string[] directories = System.IO.Directory.GetDirectories(directoryPath); foreach (string dirNameComplete in directories) { int sleshPosition = dirNameComplete.LastIndexOf(@"\"); dirName = dirNameComplete.Substring(sleshPosition + 1); TreeNode dirNode = new TreeNode(string.Format("<font color='green'>{0}</font>", dirName), dirNameComplete); dirNode.SelectAction = TreeNodeSelectAction.Expand; dirNode.Expanded = false; dirNode.PopulateOnDemand = true; rootNode.ChildNodes.Add(dirNode); } } protected void fileTree_TreeNodePopulate(object sender, TreeNodeEventArgs e) { populateNode(e.Node, e.Node.Value); } private void makeDownload(string fisicalFilePath) { if (string.IsNullOrEmpty(fisicalFilePath)) { lblMessage.Text = "File " + fisicalFilePath + " non trovato sul server!"; lblMessage.Style["color"] = "red"; return; } if (!System.IO.File.Exists(fisicalFilePath)) { lblMessage.Text = "File " + fisicalFilePath + " non trovato sul server!"; lblMessage.Style["color"] = "red"; return; } try { int positionLastSeparator = fisicalFilePath.LastIndexOf(@"\"); string simpleFileName = fisicalFilePath.Substring(positionLastSeparator + 1); Response.ContentType = "Application"; Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", simpleFileName)); Response.TransmitFile(fisicalFilePath); //Response.End(); } catch (Exception ex) { Response.ClearHeaders(); lblMessage.Text = "Eccezione durante l'accesso al file: " + ex.Message; lblMessage.Style["color"] = "red"; } } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>Untitled Page</title> <style> BODY, INPUT { Font-Family: Verdana; Font-Size: 10px; } </style> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="lblMessage" runat="server" /> </div> <asp:TreeView ID="fileTree" runat="server" ShowExpandCollapse="true" OnTreeNodePopulate="fileTree_TreeNodePopulate" > <Nodes> <asp:TreeNode Expanded="true" PopulateOnDemand="false" SelectAction="Expand" Text="Files and Directory"></asp:TreeNode> </Nodes> </asp:TreeView> </form> </body> </html>

((
Rispondi quotando
