- CTRL+W, S: Solution Explorer
- CTRL+W, E: Error list
- CTRL+W, R: Resourceview
- CTRL+W, A: Command window
- CTRL+W, T: Taskview
- CTRL+W, Q: Find Symbol Results
- CTRL+W, X: ToolboX
- CTRL+W, C: Classview
Tuesday, June 25, 2013
Visual Studio 2012, shortcut key combinations
Monday, June 03, 2013
Serialize object or list of objects using xDocument
This works for any serializable type or list of serializable type and deserialize back.
XDocument doc = new XDocument();
using (var writer = doc.CreateWriter())
{
var serializer = new DataContractSerializer(objToSerialize.GetType());
serializer.WriteObject(writer, objectToSerialize);
}
Var objectXml = doc.ToString();
To Deseralize xml back to type T.
DataContractSerializer ser = new DataContractSerializer(typeof(T));
return (T)ser.ReadObject(xmlDocument.CreateReader(), true);
you need to refer using System.Xml.Serialization; in your class type.
Thanks
Pradeep
(425)463-7804
Wednesday, April 24, 2013
Windows service and relative file path problem
I created a console application which was dependent of an xml file, I set the property of file to always copy and I always for new version of xml file inside execution directory and my console application worked until one day I wrapped that console application into windows service to run it periodically. And then this problem started.
When I run it in debug mode or console app mode it worked. I can to know about this error when I put a logging statement to log the error in eventviewer and then I found that Windows service code was looking for this file under system folder, here is error message I got in log “Could not find file 'C:\Windows\system32\ticks.xml'.”
Actually windows service runs from within system folder and their current directory (Environment.CurrentDirectory) is set to system directory and hence any relative lookup is based on this path.
To fix this problem, build your file path using AppDomain.CurrentDomain.BaseDirectory and relative path.
Thanks
Pradeep
Monday, April 01, 2013
XmlReader, XmlWriter and IsEmptyElement
<event key="Dividends" value="dividend"/> <event key="Splits" value="splits"/> <event key="Earnings" value="earnings"/> </events> |
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Attribute:
writer.WriteStartAttribute(reader.Name);
writer.WriteValue(LocalizeIt(reader, country));
break;
case XmlNodeType.Element:
bool isEmptyNode = reader.IsEmptyElement;
writer.WriteStartElement(reader.Name);
if (reader.HasAttributes)
{
WriteAttributes(writer, reader, country, culture);
}
if (isEmptyNode)
{
writer.WriteEndElement();
}
break;
case XmlNodeType.EndElement:
writer.WriteEndElement();
break;
case XmlNodeType.Text:
writer.WriteValue(LocalizeIt(reader, country));
break;
case XmlNodeType.Whitespace:
writer.WriteWhitespace(reader.Value);
break;
}
|
Make sure that you read this property on Xml Node not of node attributes, to ensure this
1. Either read it in the beginning as I did or
2. Revert to Node using MoveToElement() on reader.
Wednesday, March 27, 2013
How to learning c#
Well I do not know why to make this process faster apart from practicing it initially as much as possible. and if you have other suggestion please include in comment and I`ll update this post with credits to you :)
I am going to answer, How to learn c#, to Learn c# here are some of the posts, sites that I found useful
1. MSDN (http://msdn.microsoft.com/en-us/library/Vstudio/67ef8sbd.aspx)
MSDN is really a good source of knowledge and actually this is the preferred place to get any new feature detail, but this contains basic information and you have to try hands-on to know many hidden things or boundary conditions.
More detailed list http://msdn.microsoft.com/en-us/library/Vstudio/kx37x362.aspx
2. Channel9.msdn (http://channel9.msdn.com/Series/C-Sharp-Fundamentals-Development-for-Absolute-Beginners)
This is second in my priority list as its really a good site with lot many videos, to learn c# they have created a list of videos and they are sequentially arranged at the given URL.
3. Pluralsight Videos : http://www.pluralsight.com/training/Courses/TableOfContents/dotnet-csharp-tutorial
These courses are created by industry experts and they surely has great in depth knowledge about subject. These videos are structured and time bound. These are really good source of knowledge but these are not free, you need to have subscription to access these videos. C# videos were published in 2009, not sure if they have updated them for new version of C# or not, If you know, please provide those details in comment section.4. http://www.csharp-station.com/tutorial.aspx
This site is also well structured and they have webpages with details and also c# sample code. Good source to get practice code. They are very descriptive.5. About.com (http://cplus.about.com/od/learning1/Learn_about_C_and_how_to_write_Programs_in_It.htm)
This site is very good source of information and they have plenty of them, but only problem that I find with about.com is its not well structured and any new member get lost in their vast information.
If you know any other good source that you want me to put into this list. Please share that in comment section and I`ll include in the list.
thanks
Pradeep