asp.net - Get file path without the file -


on web page, need allow users input path file - stored in database can subsequently display 'a list of documents apply project'.

if put input type="file" on page, makes easy user browse document ... but, when form submitted, document uploaded server. don't want document, want path.

how provide functionality allow user browse file record path file without uploading file itself?

i want end showing, on web page, list of files like:

\myserver\folder20\somefolder\somefile.doc

\myserver2\folder50\somefolder\somefile.doc

i need give users easy way locate files in first place - without having laboriously open windows explorer, find file, , copy , paste path. file upload control gives access path - need - don't want file uploaded.

i not sure if want.

assuming selecting file using input type="file" html control, able complete file path in jquery , pass asp.net code behind using pagemethods (or ajax method of jquery). need create webmethod inside aspx.cs class.

you can machine name in javascript using of following lines of code

request.servervariables["remote_addr"] request.servervariables["remote_host"] request.servervariables["remote_user"] 

i not able test these have enable reverse dns lookup iis. need search on net this.

so, following steps need do

  1. your file upload control should this

    <input type="file" id="filesel" /> 
  2. put scriptmanager tag, if dont have one, in html , set enablepagemethods true as

     <asp:scriptmanager id="scriptmanager1" runat="server" enablepagemethods="true"></asp:scriptmanager> 
  3. your javascript should this.

    //in javascript  $("document").ready(function () {     $("#filesel").change(function () {         var val = $get("filesel").value; // give complete file path i.e. c:\...         alert(val);         pagemethods.sendform(val, onsucceeded, onfailed);//call webmethod on server side          //you can use ajax method not able make work          //                $.ajax({         //                    type: "post",         //                    //page name (in method should called) , method name         //                    url: "default.aspx/sendform",         //                    // if want pass parameter or data server side function can try line         //                    data: "{'filename':'" + val + "'}",         //                    //else if don't want pass value server side function leave data blank line below         //                    //                    data: "{}",         //                    contenttype: "application/json; charset=utf-8",         //                    datatype: "json",         //                    success: function (msg) {         //                        //got response server , render client         //                        alert(msg.d);         //                    }         //                });     }); });  function onsucceeded() {     alert("success"); }  function onfailed(error) {     // alert user of error.     alert("failure"); } 
  4. the webmethod present inside default.aspx.cs class as

    public partial class _default : system.web.ui.page {      [system.web.services.webmethod]     public static void sendform(string filename)     {         //do stuff here     } } 

hope able solve problem using above steps.

regards,

samar


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -