ASP.NET - Converting Text to an Image and Displaying on an ImageButton - c#

I'm creating ImageButtons on an asp.net website. Sometimes, however, an image doesn't exist for the given text and in those cases, rather than display a 'broken image', I want to simply convert the string to an image and display that.
I've seen how to create a Bitmap/Image using C# and .NET from a text string, however, I'm not sure how to utilize this for an asp.net project. The ImageButton requires an ImageUrl...so what can I do when I'm trying to dynamically create the images? Is there a way to create them and save them someplace that I can then point to or a way to create and show the images that doesn't require their being saved?
Any tips on how this could be achieved would be very much appreciated. Thanks!

Certainly possible.
Dynamically Generating and Caching Images in ASP.NET with the GeneratedImage Control

Try using a LinkButton instead. You can use File.Exists to see if the file exists, you may have to use VirtualPathUtility.ToAppRelative if you need to find the applications path to that file. If the file does not exist, you can set the LinkButtons value to just the name of the textual representation, otherwise you can put an image tag (hopefully with its alt attribute set).

It's not generally considered good practice, but you could easily add a reference to Windows Forms and use GDI+. I've done this many times. Here's a link:
http://www.codeproject.com/Articles/1827/Web-Graphics-On-The-Fly-in-ASP-NET

Related

C# Working with Images - Resources or Imagepath

i am wondering, what's the best way of working with images in c#, in a wpf application.
Someone recommend to pass the path of the image to the application, and someone recommend to use resources.
In my current project i have a listview and whenever i click a button, a image will be added. I am working with a ObservableCollection and whenever i click a button, i add the path of the image to the collection.
So, whenever i start the application i run throug the folder with the images and collect the names in an array. This way i can create the complete path to the image.
After that i use a method to shuffle the array values.
I don't know exactly how i can do that with resources, because i can't access the path of the files, but i can directly access the image.
What would you recommend, using the path or resources, and how would you handle it? What's about the performance?
I searched a lot but didn't find an answer for my "problem", maybe i used the wrong keywords...
For "After that I use a method to shuffle the array values." just use some prefix or similar to root through the resources and throw whatever you need into a collection and apply your shuffling there. All you really need to track is the name. Using Resources will be more space efficient and adds a bit more safety into things.

write the contents of application page to a file in WP7

I want to write the entire contents of my application page (eg Mainpage.xml) to a file (in Isolated Storage ) How do I do it in WP7 ? are there any methods available to parse the page contents and write it to file in windows phone 7 ?
There is no built in way to do this.
However there are a couple of approaches you could try:
If the structure is static you could try and extract the resource containing this from the DLL. For future re-use it would be easier to load the page from the DLL again though.
If you're generating a page (or part of a page) at runtime (based on user input/preferences) and you want to be able to save/reload this then just save enough information to be able to recreate it. It's unlikely that XAML would be the best format for this though.
You could create this as you build the UI. Alternatively you could walk the visual tree to get details of all that is rendered. I'd recommend recording as you go so you can more easily keep track of non-default values in the rendered objects.

Preset html files built into program?

I'm trying to create a very basic web site creator in C#. I already created the templates but have no idea how to get them in the program so the user can pick one and customize it. Is there a certain library I should look into? I've bee told this can be easily created in php but I'd rather not go down that route.
If using .NET you can use WebControl controls to display a preview of your templates and make the user decide which one he wants.
Or a list of templates and single WebControl that parse and display the HTML of the current selected list item (template) and then make the user select.
To edit, just a bunch of controls (one for each template placeholder) that updates the view of the WebControl.
In the top link you found how to do it.
P.S. Templates can be stored on XML, Plain Text, DB or any other mean.
Either store the templates as files on the web-side and use them as templates, or store them in a DB. Unless your app is not web-based, in which case the same advice pretty much applies.

display icon with respective file

Ok this is something new to me....
I have a gridview control which is displaying the files and directory names in one column.
Now i want to display the file icon of that particular file in the other column...
eg test.txt will have a different icon form image1.jpg and here.xsl
i have found two examples but don't kno if they will work or not....
http://www.codeproject.com/KB/custom-controls/AssociatedIconsImage.aspx
or
http://forums.asp.net/t/90921.aspx
how to incorporate this with my gridview..?
thanks
I found a source that should be useful for you (and with a simple google query btw.): Getting Associated Icons Using C#
.
As far as I know, there's no other way than using the shell32 library via interop, as used in the given example.
I'm not sure if there is a managed way to this... there very well could be, but the unmanaged way to get this would be to use PInvoke to call SHGetFileInfo. There is sample code on PInvoke.Net which should get you most of the way there.

Automatically Begin Upload ASP.NET

Without using a third-party control, is it possible to automatically begin uploading a file as soon as the user selects a file and the file browser window closes? I have the data struture in place as well as all the information needed to capture the data, but I need a way of knowing if the file upload has changed? Is there an event that fires, or something I can capture to achieve this?
Thanks,
George
No. Not without using a third-party control.
It looks like it is possible using a hidden <IFRAME>. Check out the AJAX File Uploader.
There are simple Silverlight and Flash solutions available as well, however.

Categories