473,387 Members | 1,561 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Write ICON data to an xml file

I have a structure that contains both 32x32 and 16x16 icons plus some text.
I want to write all this to an XML file so that I can recover the icons later
in an application. Can someone tell me how to properly serialize the
System.Drawing.Icon structure to an XML file?

The following code doesn't write the icon information to the xml file.

private void CreateXmlFile(string filename)
{

string fullPath = String.Format(@"{0}", filename);

XmlWriter xw = null;
try
{
XmlSerializer xSer = new XmlSerializer(typeof(AppIconList));
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.ConformanceLevel = ConformanceLevel.Auto;
xw = XmlWriter.Create(fullPath, settings);
xSer.Serialize(xw, this.List);
}
catch (Exception e)
{
System.Windows.MessageBox.Show(e.Message);
}
finally
{
// Ensure the file is closed.
if (xw != null)
xw.Close();
}
}

--
-----------
Thanks,
Steve
Jan 16 '08 #1
1 3880
Hi Steve,

From your description, you have an .NET appliccation which will use some
Icon file, and you also want to persist them into a XML file so that you
can retrieve them out and reuse next time, correct?

In my opinion, since Icons are actually of binary image stream, you'd
better still persist them through their binary content, however, since the
persistent storage is xml file, you can use Convertion to convert the
binary stream of the Icon from binary to string. For example,you can use
Convert.ToBase64String

#Convert..::.ToBase64String Method
http://msdn2.microsoft.com/en-us/lib...e64string.aspx

To get the binary stream of a Icon object, you can simply call its "Save"
method and provide a "MemoryStream" class, then, you can get the saved
byte[] array of your Icon object and save it into XML file.

#Icon..::.Save Method
http://msdn2.microsoft.com/en-us/lib...icon.save.aspx

Next time, you just need to extract the binary blob(convert from base64
string to binary) and use Icon's c onstructor to recreate the Icon. How do
you think?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>Thread-Topic: Write ICON data to an xml file
thread-index: AchYfDHCgoWs1fVGTGKG6m0ECW+YYg==
X-WBNR-Posting-Host: 15.235.249.70
From: =?Utf-8?B?U3RldmVU?= <St****@newsgroups.nospam>
Subject: Write ICON data to an xml file
Date: Wed, 16 Jan 2008 12:13:01 -0800

I have a structure that contains both 32x32 and 16x16 icons plus some
text.
>I want to write all this to an XML file so that I can recover the icons
later
>in an application. Can someone tell me how to properly serialize the
System.Drawing.Icon structure to an XML file?

The following code doesn't write the icon information to the xml file.

private void CreateXmlFile(string filename)
{

string fullPath = String.Format(@"{0}", filename);

XmlWriter xw = null;
try
{
XmlSerializer xSer = new
XmlSerializer(typeof(AppIconList));
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.ConformanceLevel = ConformanceLevel.Auto;
xw = XmlWriter.Create(fullPath, settings);
xSer.Serialize(xw, this.List);
}
catch (Exception e)
{
System.Windows.MessageBox.Show(e.Message);
}
finally
{
// Ensure the file is closed.
if (xw != null)
xw.Close();
}
}

--
-----------
Thanks,
Steve
Jan 17 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ed Isenberg | last post by:
I notice that a lot of Web pages have an icon that is displayed preceding the URL in the place in the browser where the URL is displayed. When I bookmark or add this to Favorites the icon is also...
8
by: Adrian | last post by:
How do I put an icon on a form using code? Thank you.
6
by: Lespaul36 | last post by:
From what I have read, there isn't really a converter to icon format..it becomes a png file. I tried: 1: Dim bmp As Bitmap = CType(Bitmap.FromFile("C:\myfolder\file.bmp"), Bitmap) 2: ...
13
by: Lou | last post by:
if I add a new item (Solution Items) to my project and its an icon(.ico), how can I reference that file when I am coding, Do I have to also add it to an image control, I don't want the file to be...
3
by: Nina | last post by:
Hi there, I assigned icon for a window's form using form's Icon property at design time. Now I want to change the icon. I tried to replace the old icon with the new icon using form's Icon...
4
by: randy1200 | last post by:
I have a Windows application that previously had the company logo "MyCompany.ico" added to the upper left-most corner. The company has since issued a new version of "MyCompany.ico" that looks...
1
by: iwdu15 | last post by:
hi, how can i get the icon associated with a certain file type? thanks -- -iwdu15
0
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this...
2
by: flarefight | last post by:
I have created an app using python and then converting it to an exe using py2exe, and have the following code: "icon_resources": in my py2exe setup file, the appFavicon works fine and it sets...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.