Showing posts with label Dot NET. Show all posts
Showing posts with label Dot NET. Show all posts

Friday, March 27, 2009

Find PublicKeyToken of signed assembly

To find the publickeytoken of an assembly, I use to drag and drop the assembly to C:\Windows\Assembly folder and then view the properties.

The better way is to use SN.EXE located under “C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin” folder.

You could integrate this tool into VS IDE using external tool features.

  1. In Visual Studio 2005, click Tools -> External Tools...
  2. Click Add and enter the following into the different fields as displayed in the following screenshot:
    • Title: Get Public Key
    • Command: C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sn.exe
    • Arguments: -Tp "$(TargetPath)"
    • Uncheck all options, except Use Output window\

Now, you have a new entry listed in the Tools menu titled Get Public Key as shown in the following screenshot:

image

 

 

 

 

Assuming you have a project open that has been configured to be signed when built, and you've built it at least one time, selecting the new Get Public Key menu item from the Tools window to get the public key token and blob in the Output window.

image 

 

 

 

Here you have assembly publictokenkey in second entry

Missing Create GUID Tool from Visual Studio 2005

I created a new VM and installed Visual studio 2005. To my horror, I could not found the Create GUID tool in Visual Studio.The Create GUID tool is often found under the Tools menu.

To fix this, I performed the following steps:

  • Reset my IDE settings.
    Select "Tools --> Import and Export Settings --> Reset All Settings" to restore the defaults. Woh, I could see the Create Guid in tool. But, it was disabled :-(

The actual file for generating GUID is guidgen.exe which would be located at “C:\Program Files\Microsoft Visual Studio 8\Common7\Tools”.

I realised that this file is missing as I didn’t installed Visual C++. I was trying to be smart :-)

Friday, October 03, 2008

IsInteger Function in C#

        public bool IsInteger(string strNumber)
        {
            Regex objNotIntPattern = new Regex("[^0-9-]");
            Regex objIntPattern = new Regex("^-[0-9]+$|^[0-9]+$");
            return !objNotIntPattern.IsMatch(strNumber) &&
                    objIntPattern.IsMatch(strNumber);
        }

Thursday, April 03, 2008

NumberToWord Function

private string[] _englishDigitMatrix = new string[]{"", "Second", "Third", "Fourth","Fifth", "Sixth", "Seventh", "Eighth","Nineth"};

public string changeNumericToWords(int number)

{

      string ret = _englishDigitMatrix.GetValue(number - 1).ToString();

       return ret;

}

 

Thursday, March 20, 2008

Testing XSLT using VS2005

In past, I use to write code using XMLTransform to test an xslt. I found a better way last night, where you could use ASP.NET 2.0 XML control.
Steps:
Create a new ASP.NET web application using VS2005
Add your source xml file to the project
Add a new xslt file to the project using ADDITEM
On the default page, add the XML control from the toolbox
Set the TransformSource property of xml control to xml file
Set the TransformSource property of xml control to xslt file

Make changes in the xslt file and run the web application and check the result

Monday, February 18, 2008

Singleton Class WinForm\WebForm

If you use static object in ASP.NET application, this works as Application object and is shared across all sessions. To create a user visible properties, we use session objects. A better way of using this is to use Singelton class. This class creates only one object and same object is refeneced again without new creation. The following code could be used to create a common Singleton class for windows and web application.

using System;
using System.Data;
using System.Configuration;
using System.Web;

namespace Common
{
///


/// Summary description for SessionConfig
///

public class StateData
{

#region PROPERTIES
string currentUser;
public string CurrentUser
{
get { return this.currentUser; }
set { this.currentUser = value; }
}
#endregion

private static StateData oInstance;

protected StateData()
{
}


public static StateData Instance
{
get
{
// If called from windows, this would be null. Use Static object then
if (System.Web.HttpContext.Current == null)
{
if (oInstance == null)
{
oInstance = new StateData();
}
return oInstance;
}
if (HttpContext.Current.Session == null || HttpContext.Current.Session["SharedData"] == null)
HttpContext.Current.Session.Add("SharedData", new StateData());


return (StateData)System.Web.HttpContext.Current.Session["SharedData"];
}
}

}
}

Wednesday, October 18, 2006

Webresource.axd or WebForm_PostBackOptions undefined problem

If would get this error if you are missing reference to Webresource.axd file.
Create an empty file with name as "Webresource.axd" and copy it to web server wwwroot and your application root folder.It should work now.

Friday, June 02, 2006

SelectALL in Compact Framework

When you want to select all the text in a textbox, you are more likely to use SelectAll function of the textbox in the GotFocus event. Ironically, once this event is fired the text is unselected. The work around is to use a timer and in timer event call SelectAll function.

private void textBox1_GotFocus(object sender, EventArgs e)
{
//Use a timer to select all
System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();
t.Interval = 10;
t.Tick += new EventHandler(t_Tick);
t.Enabled = true;
}
}
///
/// Event to select full text in textbox
///
///
///
private void t_Tick(object sender, EventArgs e)
{
((System.Windows.Forms.Timer)sender).Enabled = false; // Stop the timer
// Select all the text
textBox1.SelectAll();
}

Monday, February 06, 2006

Converting HTML text to Word

The easiest way is to copy html text to clipboard and save to word.
But when you copy an html to clipboard using copy or cut, windows add initial lines which indicates
start and end of HTML, Selection and Fragment. So, to handle this we need to
create text to be copied into compatble to above requirement

The code for this is

// Save text into clipboard
Object m = System.Reflection.Missing.Value;
DataObject clipDO = new DataObject();
// Convert into HTML with all tags before adding to clipboard
clipDO.SetData(DataFormats.Html, HtmlClipboardData(strHTML));
Clipboard.SetDataObject(clipDO, true); // Save to clipbaord

object typeHtml = (object)Word.WdPasteDataType.wdPasteHTML;
// Save from clipbaord to word
// Here s is word selection
s.PasteSpecial(ref m, ref m, ref m, ref m, ref typeHtml, ref m, ref m);



Now, convert normal html text to clipboard one.

///
/// Convert to proper html like
/// Version:1.0
///StartHTML:000000137
///EndHTML:000000204
///StartFragment:000000149
///EndFragment:000000180
///StartSelection:000000149
////EndSelection:000000180
///
///
///File
///
///
///
///
///
///
private static string HtmlClipboardData(string html)
{
StringBuilder sb = new StringBuilder();
Encoding encoding = Encoding.UTF8;
string Header = @"
Version: 1.0
StartHTML: {0:000000}
EndHTML: {1:000000}
StartFragment: {2:000000}
EndFragment: {3:000000}
";
string HtmlPrefix = @"







";
HtmlPrefix = string.Format(HtmlPrefix, encoding.WebName);

string HtmlSuffix = @"



";

// Get lengths of chunks
int HeaderLength = encoding.GetByteCount(Header);
HeaderLength -= 16; // extra formatting characters {0:000000}
int PrefixLength = encoding.GetByteCount(HtmlPrefix);
int HtmlLength = encoding.GetByteCount(html);
int SuffixLength = encoding.GetByteCount(HtmlSuffix);

// Determine locations of chunks
int StartHtml = HeaderLength;
int StartFragment = StartHtml + PrefixLength;
int EndFragment = StartFragment + HtmlLength;
int EndHtml = EndFragment + SuffixLength;

// Build the data
sb.AppendFormat(Header, StartHtml, EndHtml, StartFragment, EndFragment);
sb.Append(HtmlPrefix);
sb.Append(html);
sb.Append(HtmlSuffix);

//Console.WriteLine(sb.ToString());
return sb.ToString();
} #endregion