c# - How to download/open the file that I retrive by server path? -


i making module shows tree view of documents stores on drive in folder. retrieving well. problem documents in different format like(.pdf, .docx etc). not opening in browser on click. there shows 404.4 error. tell me how can download/open different format files through button click? following code:

   protected void page_load(system.object sender, system.eventargs e)     {         try         {             if (!page.ispostback)             {                 if (settings["directorypath"] != null)                 {                     binddirectory(settings["directorypath"].tostring());                 }                 else                 {                     binddirectory(server.mappath("~/"));                 }             }         }         catch (directorynotfoundexception dnex)         {             try             {                 system.io.directory.createdirectory("xibdir");                 binddirectory(server.mappath("xibdir"));             }             catch (accessviolationexception avex)             {                 response.write("<!--" + avex.message + "-->");             }          }         catch (exception exc) //module failed load         {             exceptions.processmoduleloadexception(this, exc);         }      }      #endregion      #region optional interfaces      /// -----------------------------------------------------------------------------     /// <summary>     /// registers module actions required interfacing portal framework     /// </summary>     /// <value></value>     /// <returns></returns>     /// <remarks></remarks>     /// <history>     /// </history>     /// -----------------------------------------------------------------------------     public moduleactioncollection moduleactions     {                 {             moduleactioncollection actions = new moduleactioncollection();             actions.add(this.getnextactionid(), localization.getstring(moduleactiontype.addcontent, this.localresourcefile), moduleactiontype.addcontent, "", "", this.editurl(), false, securityaccesslevel.edit, true, false);             return actions;         }     }      #endregion      private void binddirectory(string path)     {         try         {             system.io.directoryinfo dirroot = new system.io.directoryinfo(path);              treenode tnroot = new treenode(path);             tvdirectory.nodes.add(tnroot);              bindsubdirectory(dirroot, tnroot);             tvdirectory.collapseall();         }         catch (unauthorizedaccessexception ex)         {             treenode tnroot = new treenode("access denied");             tvdirectory.nodes.add(tnroot);         }     }      private void bindsubdirectory(system.io.directoryinfo dirparent, treenode tnparent)     {         try         {             foreach (system.io.directoryinfo dirchild in dirparent.getdirectories())             {                 //treenode tnchild = new treenode(dirchild.name);                 treenode tnchild = new treenode(dirchild.name, dirchild.fullname);                  tnparent.childnodes.add(tnchild);                  bindsubdirectory(dirchild, tnchild);             }         }         catch (unauthorizedaccessexception ex)         {             treenode tnchild = new treenode("access denied");             tnparent.childnodes.add(tnchild);         }     }       private void bindfiles(string path)     {         try         {             tvfile.nodes.clear();             system.io.directoryinfo dirfile = new system.io.directoryinfo(path);              foreach (system.io.fileinfo fifile in dirfile.getfiles("*.*"))             {                 string strfilepath = server.mappath(fifile.name);                 string strfilepaths = "~/" + fifile.fullname.substring(15);                  treenode tnfile = new treenode(fifile.name, fifile.fullname, "", strfilepaths, "_blank");                 tvfile.nodes.add(tnfile);             }         }         catch (exception ex)         {             response.write("<!--" + ex.message + "-->");         }     }     protected void tvdirectory_selectednodechanged(object sender, eventargs e)     {         try         {             string strfilepath = tvdirectory.selectednode.value;             bindfiles(tvdirectory.selectednode.value);         }         catch (exception ex)         {             response.write("<!--" + ex.message + "-->");         }     } } 

}

404.4 means web server (iis presumably) not how serve file (based on extension). if code serving other files correctly, web server configuration issue. check servers documentation adding appropriate handlers file extensions aren't working.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -