problem with image display in visual studio - c#

I have got a strange problem. Can somebody look into it please.
I have a folder called "img" in my website. I added a new image to it.
Now the strange problem is that when I give img/imagename.extension it doesn't display in the browser.
I have tried even ~/img. But ended nothing. Actually I am using the image in the spark template. I have taken an existing image and tried, it displays the existing image but not the one I have added. I was expecting may be I need to check in the newly added image but even doing that didn't end up the result.
Any ideas????
Thanks

if you using Razor use #Url.Content("~/img/yourimage.ext")

Check if authorisation rules of the folder img prevent the images from being shown e.g. to not authorised users.
Check if the image file was properly added to the solution in the VS.

Related

Cannot load photo locally in ASP.NET MVC

So, i am creating an ASP.NET(MVC5) application, on which i want to show an image using an img tag like that:
<img src='#Url.Content(Path.Combine(Server.MapPath("~/Products-Data"), product.Name, product.ThumbnailImage))' />
The problem is that no browser actually load the image. The fun thing is that the link generated by the razor engine is valid, and i can see the image if i open it from another browser tab. After some searching i noticed that in the chrome console, there was this error:
I found a lot of topics regarding this error(change settings in web.config, use the --allow-file-access-from-files flag and e.t.c), but none of these actually worked. This is going to be a real-world application ... but for the time being i need to test it locally, and check if everything works properly. Any work around's here folks ?
You just need to generate the path using relative path, resolving it to the absolute path wouldn't work, as it will be the path of the server's particular drive location which is most of the times outside of the working directory of the web application and it is not possible for the browser to fetch the resource using physical path, so it wouldn't work for you.
You would need to do do it something like :
<img src="#Url.Content(String.Format("~/Products-Data/{0}/{1}", product.Name, product.ThumbnailImage))" />
and it would be more better if you pass it via Model object the relative path and the view just have displaying code, view should not contain logic to generate the path.
Hope it helps you!

WebBrowser.DrawToBitmap() doesn't render the image

I have got into a strange situation and couldn't find a reason or resolution to it. I have a utility that creates a jpg image out of an HTML content. It is using WebBrowser.Navigate(url) and WebBrowser.DrawToBitmap() methods.
This utility has been working for a year or more by different clients on their servers. Now, one of them which could get desired images until few weeks ago, getting strange images. The image just shows the URL that I am passing to the Navigate() method. I could render the correct image from the same URL on my local machine. I checked the DocumentText property of the object and the contents was there and all the width and height was OK and no error is generated anywhere. Only the image doesn't make any sense. It is not related to the HTML contents and does the same behavior for all pages.
Does anyone knows what could be changed that caused this issue to happen? Although they have recently upgraded from Server 2008 to 2012, they claim that this rendering stopped before the upgrade. My code has not been touched. The project is built with C# and .NET 4.0.
Any help or comments is appreciated.
Behzad
It may be because of KB3057839 which has broken DrawToBitmap:
https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/9d690398-1f91-4fbd-82fa-4b663c3b558f/kb3057839-has-broken-windows-forms-controldrawtobitmap-when-called-from-application-launched-from?forum=windowsgeneraldevelopmentissue
Since this issue was introduced using the security update patch "KB3057839" . Microsoft has again released a few set of patches on July 14(Please check https://technet.microsoft.com/en-us/library/security/ms15-jul.aspx). The patch "KB3070102" resolves the issue and can be downloaded from https://technet.microsoft.com/library/security/MS15-073.

Old picture appears on web page

I have an Image on my webpage with ImageUrl="~/global1/images/mypic.gif".
I replaced the picture in the directory with another file of the same name, but the old one still appears when I load the page.
Even when I delete the file completely, the old picture still appears.
Why does it happen?
Thank You.
Step 1: Clear Browser History
Step 2: Clean and Rebuild your Project.
Step 3: Now start the Application.
if still the problem appears restart the Visual Studio IDE.
You should clear browser history first then check.
Check same thing in another browser
Clear browser cache
Re run the application
This link describes how to clear browser history.
Very often rebuilding/recompiling does the trick.
If not: Citing from another question "Old picture appears on web page":
Try adding a cachebreaker at the end of the url:
newImage.src = "http://localhost/image.jpg?" + new Date().getTime();
This will append the current timestamp automatically when you are
creating the image, and it will make the browser look again for the
image instead of retrieving the one in the cache.

Hide new folder option in telerik editor file uploading

I am using telerik rad editor in my projct. To add image I am using Image manager,while click on Image manager it opens the pop up where I can upload multiple images to the specified folder. It also showing me image editing option in same popup. My requirement is I don't want to show default image folder to user and don't want any image editing. I also want to hide add new folder option. please help me. If you have any sample code. Please share with me.
Thanks in advance.
i think the below url help you through this hope this helps:)
http://www.telerik.com/community/forums/aspnet-ajax/editor/radeditor---image-manager---removing-commands.aspx
<telerik:RadFileExplorer ID="RadFileExplorer1" Height="410px" Width="400px" TreePaneWidth="150px"
runat="Server" EnableOpenFile="false" AllowPaging="true" VisibleControls="TreeView,Toolbar,Grid,AddressBox"/>
for more info see this link http://goo.gl/k9LMuR
You can customize the dialogs so that the elements you do not want visible to the user are not, e.g. by setting their display CSS property to none or by editing the markup. See this demo for an example:
http://demos.telerik.com/aspnet-ajax/editor/examples/externaldialogspath/defaultcs.aspx. Note that just removing controls is likely to cause an error so you should test your custom dialog carefully.
Regarding the folder you show - in order to upload images you need to access the folder, so the files will be shown to the user. You can try implementing a custom provider to hide certain files, see this demo on the matter: http://demos.telerik.com/aspnet-ajax/editor/examples/dbfilebrowsercontentprovider/defaultcs.aspx.

To save webpage as image

I have to save webpage as image by passing page URL,i have found one solution on this thread Convert webpage to image from ASP.NET[^] but it doesn't give me proper image(e.g. tried URL http://www.bugmuncher.com/).
Also tried HTML to Image in C#[^] but not able to deal with IViewObject interface ,basically not able to add reference to get this interface.
I have to do something like http://www.usersnap.com does.I made it work on FF,Chrome and IE9 by using canvas element which is unfortunately not supported by IE8.
Can i get proper working solution for my need???
i think you mean taking a screenshot.
Here you are a link about it.
Capture screenshot of active window?
But here i found on the site that just you want. Please check it.
Convert webpage to image from ASP.NET
The webpage can be saved as image by 2 methods.
1. Press ctrl+p
2. Select "Send to onenote" in print prompt window.
3. Press ok.
Now the image can be saved from the microsoft office -> microsoft onenotebook and rightclick on your content. save as the image file.
Second method is by using snapshot via snipping tool.

Categories

Resources