private static bool IsNetFrameWork45()
{
// Following are the different version for .Net 4.0
//4.0.30319.1 = .NET 4.0 RTM
// 4.0.30319.269 = most common .NET 4.0 version we're seeing in the data collected from our users
// 4.0.30319.544 = another .NET 4.0 version that a small portion of our users have installed
// 4.0.30319.17626 = .NET 4.5 RC
// 4.0.30319.17929 = .NET 4.5 RTM
// 4.0.30319.18010 = current version on my Windows 8 machine
Assembly assembly = typeof(System.String).Assembly;
System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
if (fvi.FileMajorPart != 4) return false;
if (fvi.ProductPrivatePart < 17626) return false;
return true;
}
Wednesday, January 9, 2013
Function for checking if .net Framework installed
Tuesday, January 8, 2013
Mobile Web Applications with ASP.NET WebForms
http://roopeshreddy.wordpress.com/2012/12/29/mobile-web-applications-with-asp-net-webforms/
Monday, January 7, 2013
How to use UserControl in ASP.NET MVC?
1. Create UserControl as same as in the webforms. But change base class from System.Web.UI.UserControl to System.Web.Mvc.ViewUserControl
3. Then able to load by Partial view
public partial class TestUserControl : System.Web.Mvc.ViewUserControl
{
protected void Page_Load(object sender, EventArgs e)
{
this.Label1.Text = "Loaded";
}
}
2. Put this UserControl all related files into Views/Shared folder 3. Then able to load by Partial view
@Html.Partial("TestUserControl");
Asynchronously streaming video with ASP.NET Web API
http://www.strathweb.com/2013/01/asynchronously-streaming-video-with-asp-net-web-api/
Friday, January 4, 2013
How to save MailMessage into eml file by Reflection on .net framework 4.5?
////// HACK - SmtpClient does not give access to filenames when outputting e-mails to disk. The following extension method /// uses reflection to call the internal MailWriter type so that mails can be created with a specified filename. /// /// Code taken from: http://www.codeproject.com/KB/IP/smtpclientext.aspx /// /// Mail message to be serialized./// Filename of mail message.public static void Save(this MailMessage Message, string FileName) { // TODO: See if the Mono framework has serialization code we can use. Assembly assembly = typeof(SmtpClient).Assembly; Type _mailWriterType = assembly.GetType("System.Net.Mail.MailWriter"); using (FileStream _fileStream = new FileStream(FileName, FileMode.Create)) { // Get reflection info for MailWriter contructor ConstructorInfo _mailWriterContructor = _mailWriterType.GetConstructor( BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(Stream) }, null); // Construct MailWriter object with our FileStream object _mailWriter = _mailWriterContructor.Invoke(new object[] { _fileStream }); // Get reflection info for Send() method on MailMessage MethodInfo _sendMethod = typeof(MailMessage).GetMethod( "Send", BindingFlags.Instance | BindingFlags.NonPublic); // Call method passing in MailWriter _sendMethod.Invoke( Message, BindingFlags.Instance | BindingFlags.NonPublic, null, new object[] { _mailWriter, true, true }, null); // Finally get reflection info for Close() method on our MailWriter MethodInfo _closeMethod = _mailWriter.GetType().GetMethod( "Close", BindingFlags.Instance | BindingFlags.NonPublic); // Call close method _closeMethod.Invoke( _mailWriter, BindingFlags.Instance | BindingFlags.NonPublic, null, new object[] { }, null); } }
Subscribe to:
Posts (Atom)