RSS

Tag Archives: FAQs Help and Tutorials

Display Windows Application product version


Whether the application is standalone or click-once this works always

Displays version information in label named ‘lblVersionInfo’

if (ApplicationDeployment.IsNetworkDeployed)
{
    ApplicationDeployment appDeployment = ApplicationDeployment.CurrentDeployment;
    lblVersionInfo.Text = appDeployment.CurrentVersion.Major.ToString() + "." + appDeployment.CurrentVersion.MajorRevision.ToString() + "." + appDeployment.CurrentVersion.Minor.ToString() + "." + appDeployment.CurrentVersion.MinorRevision.ToString();
}
else
{
    lblVersionInfo.Text = Application.ProductVersion;
}

And do not forget to add using block in your application

using System.Deployment.Application;

Sample screen:

About Box - Product Version Dialog

About Box - Product Version Dialog

 
Leave a comment

Posted by on February 21, 2012 in .NET, C#, Winforms, WPF

 

Tags: , , , ,

Display row number in WinForms DataGridView


In WinForms Applications, to display the row number in the row header, we could use the RowPostPaint event of DataGridView control.

Usage:

Suppose grid is named as dgvUserDetails

Delegate

        this.dgvUserDetails.RowPostPaint += new System.Windows.Forms.DataGridViewRowPostPaintEventHandler(this.dgvUserDetails_RowPostPaint);

Code

private void dgvUserDetails_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
        using (SolidBrush b = new SolidBrush(dgvUserDetails.RowHeadersDefaultCellStyle.ForeColor))
        {
              e.Graphics.DrawString((e.RowIndex + 1).ToString(), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 10, e.RowBounds.Location.Y + 4);
        }
}

Don’t try to manipulate the Code part much because the X and Y are calculated co-ordinates in the row header area or you can customizse test it yourself to see the various results.

Output:

User Management Utility

 
13 Comments

Posted by on January 26, 2012 in .NET, C#, Winforms

 

Tags: , , , , , , , , ,

How to convert an IEnumerable to JSON


.Net Framework Logo

You can do it like this using .NET Framework itself and without using any 3rd party tools

using System.Web.Script.Serialization;

public class Json
{
    public string getJson()
    {
       // some code //
       var products = // IEnumerable object //
       string json = new JavaScriptSerializer().Serialize(products);
       // some code //
       return json;
    }
}

Serializing Usage:

IEnumerable<int> sequenceOfInts = new int[] { 1, 2, 3 };
IEnumerable<Foo> sequenceOfFoos = new Foo[] { new Foo() { Bar = "A" }, new Foo() { Bar = "B" } };

var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
string outputOfInts = serializer.Serialize(sequenceOfInts);
string outputOfFoos = serializer.Serialize(sequenceOfFoos);

Output:

[1,2,3]
[{"Bar":"A"},{"Bar":"B"}]

Deserializing Usage:

IEnumerable<int> sequenceOfInts = serializer.Deserialize<IEnumerable<int>>(outputOfInts);
IEnumerable<Foo> sequenceOfFoos = serializer.Deserialize<IEnumerable<Foo>>(outputOfFoos);

Reference links: StackOverflow.com

 
1 Comment

Posted by on January 25, 2012 in .NET, ASP.NET, C#, JavaScript

 

Tags: , , , , , , , ,

Printing in IIS using ASP.NET or Web services


You can try as below:

1. Changing the account that ASP.NET runs under.

The IIS Worker Process runs as Network Service and the ASP.NET Worker Process runs as ASPNET by default. So to access the Installed Printers you have to change it to run under Local System Account.

2. You can impersonate the asp.net site

When the IIS Worker Process or the ASP.NET Worker Process starts a Web application, the Web application inherits the identity of the process if impersonation is disabled. (Impersonation is the process of allowing a thread to run under a different account from its process.) However, if impersonation is enabled, each Web application runs under the user account that is authenticated by IIS or the user account that is configured in the Web.config file. Impersonation can be enabled in either of the following two ways in Web.config:

<identity impersonate="true"/>

This allows the Web application to run using the identity that was authenticated by IIS.

<identity impersonate="true"
 userName="SomeUserAccount"
 password="SomePassword"/>

This allows the Web application to run using a specific identity.

If you have the network printer in my printers then it will show up in Installed printers.

Reference links: Stackoverflow.com and Bluevisionsoftware.com

 
5 Comments

Posted by on January 24, 2012 in .NET, ASP.NET, C#, IIS

 

Tags: , , , , , , , , , , ,

How To: show loading or progress message in website in ASP.NET


ASP.NET Display “Loading…” message while update panel is updating

You can use code as below when

using Image as Loading:

 
<asp:UpdateProgress id="updateProgress" runat="server">
     <ProgressTemplate>
            <div style="position: fixed; text-align: center; height: 100%; width: 100%; top: 0; right: 0; left: 0; z-index: 9999999; background-color: #000000; opacity: 0.7;">
                    <asp:Image ID="imgUpdateProgress" runat="server" ImageUrl="~/images/ajax-loader.gif" AlternateText="Loading ..." ToolTip="Loading ..." style="padding: 10px;position:fixed;top:45%;left:50%;" />
            </div>
     </ProgressTemplate>
</asp:UpdateProgress>

using Text as Loading:

 
 <asp:UpdateProgress id="updateProgress" runat="server">
         <ProgressTemplate>
                <div style="position: fixed; text-align: center; height: 100%; width: 100%; top: 0; right: 0; left: 0; z-index: 9999999; background-color: #000000; opacity: 0.7;">
                      <span style="border-width: 0px; position: fixed; padding: 50px; background-color: #FFFFFF; font-size: 36px; left: 40%; top: 40%;">Loading ...</span>
                </div>
         </ProgressTemplate>
    </asp:UpdateProgress>


Reference: StackOverflow.com
 
Leave a comment

Posted by on January 23, 2012 in .NET, ASP.NET, CSS, JavaScript

 

Tags: , , , , , , , ,