My server url is something like 192.1.1.1:123 and my images folder in server is F:\images\1234.jpg but I published the website in C:\inetpub\wwwroot\
How can I refer to images from F:?
consider using virtual directory
<application path="/files">
<virtualDirectory path="/Images" physicalPath="F:\images" />
</application>
then in browser accessing images from 192.1.1.1:123/files/images/1234.jpg
Mode - 1
Read the image file in browser.
Implement this way in your code file.
ex.~/Content/images/img1.png
Mode - 2
After publish the code in this URL 192.1.1.1:123 then after follow the below step.
Run URL in browser.
Right click image and open in new tab then copy the URL. ex. //192.1.1.1:123/Content/images/img1.png
Paste the URL in the code you need.
Related
I have the following structure:
AppName
Content
img
file.png
I can navigate directly to mysite.com/Content/img/file.png without any issues.
However when I add test.txt to img and set to Copy Always and type Content (same as file.png), I get No webpage was found for the web address when visiting the link, when I want to be able to enable folks to download the publicly accessible file (no auth needed), just like the image. Why isn't this working?
I can see test.txt in the bin folder of the app. Does something else need to be configured to enable direct file downloads?
Make sure your IIS site settings or web.config have mime type associated with .txt extension.
https://www.iis.net/configreference/system.webserver/staticcontent/mimemap
I am using acnchor tag to download file on click of it but on click the file fails to download and shows Failed-Network error in in chrome browser.
I changed my anchor tag on different ways but non of them working
<td>#file.FileName</td>
<td><a href="#file.FilePath" download>#file.FileName</a></td>
<td><a href="#file.FilePath" download=#file.FileName>#file.FileName</a></td>
What is problem in it?
This is a client-server issue. That path exists on the server, but the download is initiated by the client. The client doesn't have access to the server's filesystem, so it fails. If you need stuff in that directory available for download, create a virtual directory under your site that points to that path, then link the user to the file under the virtual directory, e.g.:
Click me!
There is an image in Images folder in my solution and I have an image controller on my page. and on a button click I set the URL of the image like this,
imgDisp.ImageUrl = #"~/Images/American.jpg";
But the image is not showing up on the browser when I run the code. The image is present in the specified folder and I didnt mention any URL in tag either. What am I missing ? The image URL should be mentioned the above way when running in local host too or should it be done differently ? Thanks in advance for the reply.
I actually have a C# winform application which load images from my computer C://images/... with the Image object and the function Fromfile.
Image.FromFile(Path);
but in my web application (ASP)
<asp:Image ID="viewPhoto" runat="server" Width="550px" Height="400px"/>
I use the attribute ImageURL.
viewPhoto.ImageURL = Path
But the problem is that it doesn't find the correct path because with this way. The path will be http://localhost:3656/C://images....
I would like to load an image directly from my server to have the correct path for both of my applications.(web ASP and winform)
Image.FromFile(/images/myimage.jpg)
This actually doesn't work because the program doesn't find any photo in this path.
First of all i think that images you are trying to show are not in web application folder / virtual directory. Move images folder to your web application folder and then use:
Page.ResolveClientUrl("images/test.jpg");
or for server side:
Server.MapPath("images/test.jpg");
If you dont want to move images to your web folder then your only choice is to write HttpHandler which will read images from C:\images folder and transmit it to the client. This will also require some specific permissions for your web app IIS user to access some folder outside the web app scope.
You can see the sample of HttpHandler here: Thumbnailer HTTP Handler
ASP.Net image simply renders the ImageURL to the client browser, this will then try to load that image from the location specified, this typically needs to be a resource available via your website.
Try moving your images inside your web root then you can access them like :
viewPhoto.ImageUrl = "~/images/yourimage.jpg";
As im sure you know your <asp:Image> element is actually creating an html <img> element that will instruct the browser to request the image from the browser.
Image.FromFile will give you an image object on the server side but it won't be much use for your clients browser.
As #HABJAN said, you need to map the path from your local file to a relative web URI and to do that you can use Server.MapPath. However your images will need to be inside your asp.net project folder which is asccessible by the web server in order for it to serve the file.
If you really want to share the paths in some sort of shared constant assembly I suggest you make your windows application work with relative paths and duplicate the images folder structure for both the windows app and the web app.
I found the quickest way to resolve this was to assign the image path as a css attribute. The only downside of this is that if you are looking to display a large amount of images in a repeater you would not want to use this, but if you have one or two images you can use this.
<style type="text/css">
#errorImage{
background: url(/path/path/images/image.jpg);
background-size: contain;
height: 100px;
width: 100px;
}
</style>
<div id="errorImage"><div>
Using the path you are using now (http://localhost:3656/C://images....), the application will look for a /C://images... folder in your app directory on the web server. I believe you should create an images directory in your application folder and server the images from there so that you could reference the images using a relative path.
I need to display an Image in web page. But the Image doesn't exist in the Web directory. If the image is under web directory I know that just "../Images/TN/my.jpg" will work. But the image is available in "D:\Images\TN\my.jpg" and My web site is deployed in "C:\apps\mywebsite".
How do I convert the "D:\Images\TN\my.jpg" path to a relative path so that the Image will be visible in web page?
You cant show images if they are not in a virtual directory.
Try holding then in your application folder itself or if its not feasible then make your Folder holding the image as a virtual directory in the IIS and mount it in your application folder.
Here's what you need to do (way i prefer),
Open IIS manager.
In Connections under Sites Select your Website and RightClick on it.
Select `Add Virtual Directory`... from the Context menu.
In The dialogue box that opens Enter the Alias name of your choice like **`"GlobalImages"`**
Browse the physical path of the Folder you want to and Select it and Click OK.
You will have it available for relative url in that website. like
www.example.com/GlobalImages
When you set that in IIS, it is automatically added to your Solution's Project.
Here is the MSDN link if you want..
http://msdn.microsoft.com/en-us/library/ms751432.aspx
Easiest thing to do is probably set up a handler and use the generic image name. While local, point to the D:. While on the server, point to the web path. (At least so long as you're not keeping them within the virtual directory that is).
TO fetch this point, we always write the absolute directory for images or other resource.But if the resource in the web server, i use the relative directory.