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.

8
  • 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. Commented Jan 4, 2013 at 17:02
  • What do you mean by "working folder"? There is no "working folder" for JavaScript in the browser. Commented Jan 4, 2013 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 Commented Jan 4, 2013 at 17:04
  • Post your code. How have you put it in the session variable and how are you outputting it? Commented Jan 4, 2013 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 Commented Jan 4, 2013 at 17:06

3 Answers 3

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 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks verymuch Icarus, thats exactly i want, my task is to do so, let the risk be on manager, he is not listening.
1

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

Comments

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.

3 Comments

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
You need to store the path to create the file in an <asp:HiddenField /> 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.
thanks Brian Mains, i got some help for using Icarus method and your hidden field idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.