0

How to get Physical path of working folder in jscript or jquery?

What i need is when a dropdown is selected or if a button is clicked i need to get complete path of the working folder.

ex:

var x="path" here x should be  x=E:/projects/projectname/xyz.aspx.  

i dont want url of current docuent, i want complete path, so that i can generate new aspx page and place in that folder dynamically.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
SHIVA P.
  • 17
  • 1
  • 4
  • 1
    You can't get the physical path from the client, that would be a security risk. You shouldn't expose the physical paths of your pages to the world. – Kevin B Jan 04 '13 at 17:02
  • What do you mean by "working folder"? There is no "working folder" for JavaScript in the browser. – Oded Jan 04 '13 at 17:04
  • i have used Server.Mappath in C# and placed the path in session, but when i call the session in aspx, it is omitting the backslashes and giving complete path as a string. please help with other options – SHIVA P. Jan 04 '13 at 17:04
  • Post your code. How have you put it in the session variable and how are you outputting it? – Oded Jan 04 '13 at 17:05
  • i need to get dynamically a complete folder path like c:\Project\ProjectFolder\xyz.aspx. in javascript/jquery, so that i can use the path and place a newpage generated dynamically – SHIVA P. Jan 04 '13 at 17:06
  • in .cs file--> string Dpath1 = Server.MapPath(""); Session["path"] = Dpath1; and in aspx iam calling this way--->
    – SHIVA P. Jan 04 '13 at 17:07
  • Iam getting the path but with out backslashes '\', it is returning as a complete string like-->E:ProjectProjectFolderXYZ.aspx in aspx. but working fine in cs file. is there any other way of doing so? – SHIVA P. Jan 04 '13 at 17:10
  • Add your code, properly formatted, to your question, not in comments – robertc Jan 04 '13 at 17:14

3 Answers3

2

I think you are looking for something like this:

var x = ('<%=HttpUtility.JavaScriptStringEncode(Server.MapPath(Request.Url.LocalPath))%>');

Now, how useful is that information on the client side is something that's not clear to me, besides being risky, in my opinion...

On my PC, it prints this if I do console.log(x):

\\company\home_drives$\rsanchez\visual studio 2012\Projects\test\test\Default.aspx 
Icarus
  • 63,293
  • 14
  • 100
  • 115
  • Thanks verymuch Icarus, thats exactly i want, my task is to do so, let the risk be on manager, he is not listening. – SHIVA P. Jan 04 '13 at 17:25
1

Browser run in sandboxes, that mean that client scripting is forbidden to access the file system.

HMarioD
  • 842
  • 10
  • 18
0

You would need to collect all of the physical paths on the server, and pass them to the client. If you wanted the entire folder structure, you'd have to pass it down to the client and construct the folder structure.

I assume you are referring to something like a file manager that a hosting company might use.

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
  • ok what exactly i want is: when certain event occurs i have to dynamically create a .aspx web page and place it in the concerned folder, for this i have achieved doing task, but i have given complete 'path'(E"/folder1/folder/x.aspx) where to save the new page, but if i post this on to server, path changes then error occurs "cannot find the path", so for this i need some idea or javascript code for physical path". iam doing this in Handler passing variables through javascript/jquery – SHIVA P. Jan 04 '13 at 17:17
  • You need to store the path to create the file in an `` control if you are using web forms, or in a hidden field for MVC. This posts back to the server in its original form, and then should resolve that problem. – Brian Mains Jan 04 '13 at 17:21
  • thanks Brian Mains, i got some help for using Icarus method and your hidden field idea. – SHIVA P. Jan 04 '13 at 17:26