show image from another server HTML - c#

I have this image URL i got from database.
\\Imagepath\ImageFolder\image.png
but i need to put in a img tag in html to show the image in the page, i try to do this way
<img src='\\Imagepath\ImageFolder\image.png'/>
but the page adds the default url for localhost, ie.
http://localhost:1234/\\Imagepath\ImageFolder\image.png
I need your helpfor trying to get the image from that server URL.
I have a lot of images around 6,200 so is not an option to download, i'm show the images in a table.
NOTE: i know the img tag not accept the URL like i have, but maybe you have an idea to do in ASP.NET, i apretiate your help.
NOTE 2:i'm using ASP.NET MVC.

Paths starting with \\ are UNC paths, they are not URLs. In a browser, you have to use a URL to load an image.
The browser is assuming you've tried to specify a relative URL, and is attempting to add the current URL by default in order to fully qualify it and then make a request to it to get the image.
You need to map the path to a virtual directory in your webserver and then point the image's src property at the URL of that virtual directory.
Alternatively, if that's not a workable solution you could write an MVC action method which takes the name of the image file as a parameter and then loads the image from the UNC path in the background and returns the data in a binary response to the browser.

Related

Access image on IIS server from client via Url | ASP .Net

My application is an Api ASP.Net, and I save the images in the "wwwroot" folder
Content
When I publish my application that structure is created as well and I want to access the images through a URL
From Client Angular 2
<img src="{{ 'http://192.168.1.20/Api/api/uploads/Koala.jpg'}} " >
(Not Found)
I must mention, that my application is published locally, and users connected to the network must access the images
Question
How to access the image found on the IIS server with the Url?
I am right?
Correct me if I'm wrong
Thank you all
First try to access the image url on the browser i.e.,
http://localhost/Api/api/uploads/Koala.jpg
If it displays the image then there is not problem with you IIS hosting.
Now try the same url from a different machine in the network i.e.,
http://192.168.1.20/Api/api/uploads/Koala.jpg (from a different machine)
If it does not work then make sure that you machine accepts http inbound traffic over the network.
Use tilde ~ for relative URL in paths:
<img src="{{ '~/uploads/Koala.jpg'}} " >
Based on my understanding, you shouldn't specify the full URL in <img src="{{ }}">.
If you want to specify full URL in Src attribute, you don't need angular. You should just remove {{''}} and modify the URL to
<img src="http://192.168.1.20/Api/api/uploads/Koala.jpg" >
If you want to use angular2 in this case, you should just modify the URL like
<img src="{{imageUrl}}">
Then declare the variable imageUrl in Component.

Facebook C# SDK Windows Phone Invalid URI: The Uri string is too long

I am trying to post an image as a staging resource to Facebook. The path for uploading staging resource image is me/staging_resources which works perfectly with the iOS SDK. However, when I try to post the image:
dynamic result = await Client.PostTaskAsync("/me/staging_resources", image);
I am getting an exception in Facebook.DLL telling that the URI is too long (after about 15 seconds). The image object is a dynamic object with a file member which is the byte array of a JPEG file. I've tried lots of other ways of posting the image data but always got different errors about not providing correct image data, and now I'm not getting those errors, it possibly is the way to post the image (it even complained if I didn't make a file member of the object, it explicitly want file to be the binary image data). What could I be doing wrong, and how can I upload a staging resource to Facebook?
Open the WMAppManifest.xml file and search for the tag right after the Tokens declaration.
Try removing the hyphens from the name property of the protocol tag inside the tag. I am assuming you are using a Uri Mapper for your facebook integration.
The tag should look something like below:
<Extensions>
<Protocol Name="msft-4ff532b5c47f4b42bb68f271cf45f4321" NavUriFragment="encodedLaunchUri=%s" TaskID="_default" />
</Extensions>
The string after the msft is your app id in the windows store.

Use HTML string from Server Requets, and create the web page without saving it a file [in C#]

I´m sending the value of a variable via POST to a PHP page in C#. I get the data stream from the server that has all the web page in HTML with the value of the POST. This information is stored in a string variable.
I would like to open a browser and show the web page (maybe using System.Diagnostics.Process.Start("URL")), without having to save it in a file, this is showing the page in the moment and, when the browser is closed, no file is stored in the server.
Any idea?
Drop a WebBrowser control into a new form webBrowser1 and set its DocumentTextProperty to your result html
webBrowser1.DocumentText = ("<html><body>hello world</body></html>");
source:
<html><body>hello world</body></html>
You aren't going to be able to do that in an agnostic way.
If you simply wanted to open the URL in a browser, then using the Process class would work.
Unfortunately, in your case, you already have the content from creating the POST to the server, and you really want to stream that response in your application to the browser.
It's possible among the some browsers, but it's not able to be done in an agnostic way (and it's complicated even when targeting a specific browser).
To complicate matters, you want the browser to believe that the stream you are sending it is really coming from the server, when in reality, it's not.
I believe that your best bet would be to save the response to the file system in a temp file. However, before you do, add the <base> tag to the file with the URL that the file came from. This way, relative URLs will resolve correctly when rendered in the browser.
Then, just open the temporary file in the browser using the Process class.

WebBrowser not loading my page

I have a WebBrowser element in my UI, I can make it navigate to a hosted page, but when I want it to load a local webpage (which is in my solution resources), which is the exact html file hosted on internet, it just shows a blank page.
browser.Navigate(new Uri("test.html", UriKind.Relative));
If I change the UriKind or the page name it shows an error that the file could not be found, so I know the browser is finding the webpage correctly but it won't render it.
I need to do this because I want to show the page while the user is offline.
If the html file has a build action of Content you can access it directly from the install location if you set a relative path.
If you want to be able to navigate between pages or include other resources in the file (including external css, js or even images) then you'll either need to copy all the files to IsolatedStorage and view them from there or host them externally.
Edit:
MSDN has an article which explains copying files to IsolatedStorage, so they can be viewed in the WebBrowser control, at http://msdn.microsoft.com/en-us/library/ff431811(v=vs.92).aspx
The browser cannot read a resource from your App/Dll. However, it you have the file in the same folder as you application you could do:
var home = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
browser.Navigate(new Uri("file://" + home + "/test.html");

Get redirected url from code

I'm using an API which, given a url, redirects to a file on the server. The file names have "_s,_m and _l" appended to the end (small, medium, large). However, since the url's querystring is parsed dynamically, I don't retrieve the actual file name. The image displays correctly, but is it possible to retrieve the filename of the image file from the code? (i.e. where the url has redirected to)?
e.g. http://api.somesite.com/getimage?small (this is what I enter)
"http://somesite.com/images/userimage_s.png" (this is where it redirects to. I would like to get this address from code)
Thanks for any advice
Sounds to me like you are trying to access some images you shouldn't access programmatically ;-)
You could access the given URL with an HTTP client (opening the stream with a stream reader might already suffice) and watch out for a Location header, which will most likely contain the URL you are searching for.

Categories