I need to access a network folder in
\\p3clfs\xyz\test.tiff
Then:
String image = #"\\p3clfs\xyz\test.tiff";
MyClass.OpenUrl(image)
Error: c:\inetpub\wwwroot\p3clfs\xyz\ does not exist!
How can I open the URL without "c:\inetpub\wwwroot\"?
If you need to open a network path (so, something based on the file system,) as a URL, your string needs to be something like this:
String image = #"file://p3clfs/xyz/test.tiff";
Actually the solution was to create a virtual directory in IIS.
Related
What is the best way to get this folder path programmatically :
Windows\system32\config\systemprofile\AppData\Local ?
Sample code
HttpContext.Current.Server.MapPath();
System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
I can't write comments sorry. What are you using the path for? Where is the application stored? This will get you there??
string path = "C:\\Windows\system32\config\systemprofile\AppData\Local";
Provided C: is the name of the drive.
You really need to expand on your question a little bit.
Is this a duplicate question??
How to read existing text files without defining path
I think you can use Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData
In my project like this
string configPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MyProject", "SERVICER", "config.ini");
It get Application Data Directory for all user ( contain System, Service, Guest,... ). I use it for save config of Service!!
You can get the path this way:
Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData)
I have a Member Register aspx page.
ACCOUNT(user,pass,mail,privilege)
When a user is registerd sucessfully, if the privilege == "lecturer" --> a folder is created which folder's name= user.
Take a look at my code below:
if(privilege=="lecturer")
{
string path = this.Server.MapPath("~/Lecturer/"); // path="D:\\C#Projects\\website\\Lecturer\\"
string targetPath = path + #"\";
System.IO.Directory.CreateDirectory(Server.MapPath(targetPath+newuser));
}
It has an error: 'D:/C#Projects/website/Lecturer/david' is a physical path, but a virtual path was expected. Why???
I really want to create a david folder in Lecturer folder. Help???
You do not need to use Server.MapPath again as you have already converted the virtual path to physical path.
Change
System.IO.Directory.CreateDirectory(Server.MapPath(targetPath+newuser));
To
System.IO.Directory.CreateDirectory(targetPath+newuser);
If you already have a physical path D:\\C#Projects\\website\\Lecturer\\, it doesn't make sense to call Server.MapPath
You can try this:-
var files = Directory.GetFiles(#"D:\C#Projects\website\Lecturer");
or simply try this:-
System.IO.Directory.CreateDirectory(targetPath+newuser);
What i Want to Do!
I want to show an image using image control. The source image is on file directory. The location of file is C:// directory while my project (Virtual Directory) is on D://. I want to set image source at page load.
What i have Done!
Put image control on my .aspx page.
On page load set imageurl to my suggested url
Following is the code I've written
Dim urls As List(Of String) = TryCast(Session("SliderUrls"), List(Of String))
Dim url As String = urls.Item(4)
Image1.ImageUrl = url
Note
url value is assigned properly. There no issue in url. On internet at some websites I've read that asp.net don't allow us to access resources outside virtual directory. So do you think that this may be the problem that i'm facing? and if so then how can i generate url for another virtual directory. Like i have a virtual directory on D://myproject and another virtual directory C://files. How can i generate url for Virtual directory on C://file while working in project which is in Virtual Directory D://myprojec.
The urls / paths have to be virtual and not physical.
Even though you've made the directory virtual, you appear to be trying to use the physical path instead.
Trying to use the physical path (C:/path) will not work.
Try using the base url of the other virtual directory and build your url from that.
For instance if the virtual directory is http://localhost/media
use that as the base url and attach the resources from there http://localhost/media/image.jpg
Dim baseUrl as String = "http://localhost/files"
Image1.ImageUrl = baseUrl + "/" + System.IO.Path.GetFileName(urls.Item(4))
I'm assuming the urls contains only the filenames (image.jpg for instance)
you can also store the baseUrl in web.config appSettings
// Set default workspace directory
string initialDirectoryString = #"C:\work\";
// Check if remote session, and get the local drive location
if(System.Windows.Forms.SystemInformation.TerminalServerSession) {
initialDirectoryString = #"\\tsclient\C\work\";
}
Originally when I wrote the above code, I was under the impression that we could create a directory in C:\ to write to, but from what I've been told, the only location they have acces to is the My Documents directory.
So, I know I can retrieve the local Environment.SpecialFolder with:
string path = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal);
The problem is how to retrieve from the client machine. I thought about retrieving the path from the server and prepending \\tsclient\ (and removing the : from C: etc.), but then if the My Documents directory isn't the same on the client as (V: instead of D:, for example), then I would get an Access Denied when I try to write to the location.
Is there a way to that I can specify a string similar to CMD where you can use %USERPROFILE%/My Documents, but with tsclient?
Edit: I found that I can use Environment.ExpandEnvironmentalVariables() to change the %USERPROFILE%\My Documents to an absolute path.
string MyDocumentsLocation = Environment.ExpandEnvironmentVariables(#"%USERPROFILE%\My Documents");
Hi I am developing an asp.net web application. I have to access one of the image in images folder in root directory. I am using following code in my code behind file.
string imageDirectory = HttpContext.Current.Server.MapPath("~/images/");
string imageUrl = imageDirectory + "/img1.bmp";
This works fine in my local machine. My question is does this code work when I move my application to production ?
It should as long as you have an application root/virtual directory for your site.
Also, you can combine these two lines into:
string imageUrl = HttpContext.Current.Server.MapPath("~/images/img1.bmp");
If you're thinking of putting imageUrl into an <img> tag, then no, it won't work. Server.MapPath will return your file or directory as a local Windows file/directory name, so something like "C:\WebRoot\MyWebApplication". If you send this to the browser, obviously, the browser won't pick up the image.
What you can do is something like:
string imageUrl = ResolveClientUrl("~/images/myImage.gif");