Suppose I have an Image located at “C:\A\mah” Or “E:\A\mah” my question is can I check the URL Path of such an image? If yes then how? Which will lots help me to put right URL path in my Asp.Net Web Application.
If those images are not within your project folder, you may need to create a virtual folder (say myImages) and then access images.
#Url.Content("~/myImages/imgName.ext")
Otherwise you could use
#Url.Content("~/path_relative_to_main_folder/imgName.ext")
Never use exact locations. It'll give you a headache. Instead, put a folder in your site's directory somewhere and then reference it with relative paths. For example:
<img src="#Url.Content("~/Images/ABC.png")" />
This means it is looking for the Images folder in your project's root directory.
Related
I have a JavaScript function that creates a fading slideshow. It uses images in the directory:
"wwwroot/images/backgrounds"
If I load a page that's directly inside the Pages folder, the images load properly. But if I load a page that's inside a subfolder, the browser tries to get the images from inside that folder instead of from the root folder.
So instead of
"localhost/images/backgrounds/bg1.jpg"
I get
"localhost/subfolder in 'Pages' folder/images/backgrounds/bg1.jpg"
I'm still new to this, so I'm not sure why the wwwroot folder isn't serving the images properly, but I set my default page to one in the same subfolder and it works perfectly, so I'm at a loss at to what's wrong.
Any ideas or solutions would be greatly appreciated at this point.
You're loading your images from a relative path - that is, the path that's exactly under the current directory. You want it to be based on an absolute path - that is, off of the same directory, no matter where the page is. To do that, use a slash in the beginning of your path: /wwwroot/images/backgrounds
This is actually by design - imagine you had sub-directories in your web application that needed their own images. You can then load an image, like images/pageBackground.png that's relative to each page the user is on - very convenient! Just remember that leading slash - which means start this path from
the virtual root of the application instead of the current sub-directory - and you'll get the right file!
sorry first time user and currently learning c# at uni, i'm working on an assignment and i'm trying to get the file path to work on the memory stick as that's what i need to hand it in on, thanks many regards
I'm not completely sure what your question is by I think what you're talking about is absolute vs relative paths. If you use an absolute path like "C:\users\yourname\blalba\project\stuff", then it's obviously only going to only work on your computer. However, you mostly all of the time want to use relative paths. Relative paths have the root directory of the build output files for your project; where your .exe file is built for your project. This is usually in "projectdir\bin\debug" or "projectdir\bin\release". So if you put for example a file called 'test.txt' in that directory, you can simply put the relative path "test.txt" instead of "C:\users\yourname\blalba\project\bin\debug\test.txt". If you were to put 'test.txt' in the project directory, you can use the relative path "....\test.txt". "..\" means navigating one step back.
The path to the directory containing the files you are looking for is "F:\Mod005244, 1715840". The "1715840 JH" is just the name of the drive. You access different drives via the drive letter. In this case, the drive letter "F" was assigned to your flash drive.
I would suggest making the file path configurable or request input from the user of the program as the drive letter of a flash drive will not always be "F". There are even classes (such as FileBrowserDialog) that will open a graphical file browser dialog and prompt the user to navigate and select a file.
I have an Image Path which is of D: drive and I want to display that Image on my Image Control of asp.net.So, how to provide file path to Image.ImageUrl?
"D:/Folder/001_001.jpg"
I tried with server.MapPath() method but doesn't work.
If you're deploying in IIS, you could create a virtual directory Images that would point towards D:/Folder, then you could set your ImageUrl to ~/Images/001_001.jpg.jpg.
An alternative solution could be to create a symlink between the two folders. You would run something like the following in cmd mklink /D ""D:/Folder" "[YouProjectPath]/Images", then set your ImageUrl to ~/Images/001_001.jpg.jpg. I would stay away from this though as it would only work on a machine where the project lives in the exact same path as yours.
You can make local path as following "file:///D:/Folder/001_001.jpg".
However, it's strongly not recommended to use this practice even if your site is planned to stay on your local computer only and will never been deployed to real Internet. You should copy / upload the file to your site's subdirectory 'Images' and then use the relative path '~/Images/001_001.jpg'.
i have a picture box in my win forms app. the question is, how can i make the image load from a directory within that application,
for example, i have a program and it lies under Debug directory. Now i have an image located under Debug/source/images/logo.png. I dont want to make use of resources file (embedded within the assembly)
How can i point it towards that path, instead of getting the image/picture from the local resources file.
Try this
String.Format(#"{0}\myDesiredPath\MyFile.MyExtension",System.Reflection.Assembly.GetExecutingAssembly().Location);
There are a number of ways to do this, you can use the ImageLocation property or the Load method to specify the path just take a look at the documentation here
Trying to display an image in the webpage tried like below.
Image1.ImageUrl = "C:\\Users\\naresh\\documents\\visual studio 2010\\Projects\\Vacancy\\Vacancy\\Files\\3\\710d7a38-5a4d-44fc-883f-5996150ba507.jpg";
Image2.ImageUrl = "C:\\Users\\naresh\\Desktop\\710d7a38-5a4d-44fc-883f-5996150ba507.jpg";
Second one Worked but first one didn't. I think the problem is with the spaces in the path. How can I resolve this problem?
Why do you not use a relative path to the location of your site? The path will be shorter and when you will port the web site on production server the image will still work (if the image is port to the server)
May be with the Vacancy which you have given two times. Check it, if its the mistake.
You can try to replace the spaces with %20.
But I wonder if that's the problem because the image is located at your local disk. Is this webpage only running on your local machine? Does the image exist?
Put quoted quotation marks into the string, e.g.:
Image1.ImageUrl = "\"C:\\Users\\naresh\\documents\\visual studio 2010\\Projects\\Vacancy\\Vacancy\\Files\\3\\710d7a38-5a4d-44fc-883f-5996150ba507.jpg\"";
Try giving the virtual directory path (create a virtual directory for the image folder. If it is in the root itself use the http://systemName/virtualDirectoryName/ImageFolder/image1.jpg) instead of physical path as follows:
Image1.ImageUrl=http://systemName/virtualDirectoryName/ImageFolder/image1.jpg
Hope this helps..
You are doing anyway very bad things in there. You should use Server.MapPath to resolve dynamically an IIS relative path into the file system path and you should not, never ever, load an image from the user's folders.
Put the image inside a subfolder in your web application, like for example create a folder called images at the same level where your aspx pages are.