A personal repository of technical notes. - CSC

Copy Formatted Source Code Into Blog Entry

Problem
Need to be able to display copied source code from editing tools with original formatting in a blog entry.

Solution
Use a combination of Microsoft Word and manual editing to generate the necessary markup.

Note: These steps were tested with blogspot.com and Word 2010.
  • Copy code to clipboard from editor such as Visual Studio, MS SQL Server Management Studio query, etc.
  • Paste into Word.
  • Replace all < with &lt;
  • Replace all > with &gt;
  • Copy code from Word.
  • Paste into blog post in "Compose" mode.
  • Publish.

Note: These steps were tested with blogspot.com and Word 2003.
  • Copy code to clipboard from editor such as Visual Studio, MS SQL Server Management Studio query, etc.
  • Paste into Word.
  • Replace all < with &lt;
  • Replace all > with &gt;
  • Copy code from Word.
  • Paste into blog post in "Compose" mode.
  • Switch to "Edit Html" mode.
  • Copy entire content from blog post.
  • Paste into text editor.
  • Delete all content before the first "<style>" tag.
  • Replace all occurrences of "</p>  <p" with "</p><p".
  • Put tag at beginning: "<pre>".
  • Put tag at end: "</pre>".
  • Copy code from text editor.
  • Paste into blog post in "Edit Html" mode.
  • Publish.

Type Exists in Both DLLs

Problem
Have two versions of a DLL that use the same namespaces and class names.

Project compliation throws the following error:

The type 'MyNamespace.MyClass' exists in both 'MyDLLv1.dll' and 'MyDLLv2.dll'
error CS0433: The type 'MyNamespace.MyClass' exists in both 'MyDLLv1.dll' and 'MyDLLv2.dll'


Solution
Use an external assembly alias.
  1. Specify "Aliases" property of DLL reference.
    1. In Visual Studio Solution Explorer, open References folder.
    2. Right-click DLL reference, select Properties
    3. Enter alias value in "Aliases" property.
    4. Example: Alias to MyDLLv1.dll reference could be "LegacyMyDLL".
  2. Specify alias in C# source code:

// Old way

using MyNamespace;

// New way

extern alias LegacyMyDLL;

using LegacyMyDLL.MyNamespace;

Microsoft References
Note: Could find no Microsoft references for specifying "Aliases" property of DLL reference within Visual Studio. Only for specifying compilation command line parameter.

"/reference (Import Metadata) (C#)." MSDN: Microsoft Development, MSDN Subscriptions, Resources, and More. 22 July 2009 http://msdn.microsoft.com/en-us/library/yabyz3h4(VS.80).aspx.

"Extern alias (C#)." MSDN: Microsoft Development, MSDN Subscriptions, Resources, and More. 22 July 2009 http://msdn.microsoft.com/en-us/library/ms173212(VS.80).aspx.

"How to: Use the Namespace Alias Qualifier (C#)." MSDN: Microsoft Development, MSDN Subscriptions, Resources, and More. 22 July 2009 http://msdn.microsoft.com/en-us/library/c3ay4x3d(VS.80).aspx.

Other References
"What use is the Aliases property of assembly references in Visual Studio 8. -." Stack Overflow. 22 July 2009 http://stackoverflow.com/questions/286632/what-use-is-the-aliases-property-of-assembly-references-in-visual-studio-8.

"Enhancements in Assemblies and Versioning in Visual Studio 2005." C#, Visual Studio 2008, Silverlight, ASP.NET, WPF, WCF, WF, and Windows Vista Community. 22 July 2009 http://www.c-sharpcorner.com/UploadFile/rambab/Assembly04292006002740AM/Assembly.aspx?ArticleID=69edb807-8118-4933-8366-773e87ee80ad.

Windows Command Line Tips

Command to determine location of program in command prompt
Description from where /?
Displays the location of files that match the search pattern.
By default, the search is done along the current directory and
in the paths specified by the PATH environment variable.

Example:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64
> where ildasm
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64\ildasm.exe


Copy command output to clipboard
dir | clip

Delete all folders within a folder (Windows XP)
FOR /D %f IN ("C:\MyFolderWithOtherFolders\*.*") DO RMDIR /S /Q "%f"

Delete all folders within a folder (Windows 7, Windows Server 2008, Windows Vista)
forfiles /s /p "C:\MyTestFolder" /c "cmd /c if @ISDIR==TRUE RMDIR /S /Q @PATH"

Forfiles
This is a utility for selecting files and executing a command on them. Applies To: Windows 7, Windows Server 2008, Windows Vista.

Examples:

Display all subfolders
forfiles /s /p "C:\MyTestFolder" /c "cmd /c if @ISDIR==TRUE echo @PATH @ISDIR"

Delete all files older than 30 days:
forfiles /p "C:\MyFolderWithFiles\" /s /m *.* /d -30 /c "cmd /c del @path"

See "Forfiles." Resources and Tools for IT Professionals | TechNet. N.p., n.d. Web. 8 Oct. 2012. <http://technet.microsoft.com/en-us/library/cc753551(v=ws.10).aspx>.

Open IIS Manager at a command prompt
  1. On the Start menu, click Run.
  2. In the Open dialog box, type inetmgr, and then click OK.
See
"How To: Open IIS Manager." MSDN | Microsoft Development, Subscriptions, Resources, and More. Web. 14 July 2010. <http://msdn.microsoft.com/en-us/library/bb763170.aspx>.

Commands to Display/Remove Read-Only Attributes
REM Displays files with read-only attributes set in specified directory and all subdirectories.
dir /ar /s

REM Clears the read-only file attribute from matching files in the current folder and all subfolders.
attrib -r /s


Command Line to Lock Computer (Windows 7, XP)
rundll32.exe user32.dll, LockWorkStation

Updates
2015-02-13 Added "Command to determine location of program in command prompt"
2013-08-02 Added "Copy command output to clipboard"
2012-10-08 Added "Forfiles"
2011-08-25 Added "Delete all folders within a folder"
2011-03-04 Added "Command Line to Lock Computer"

Google Analytics Site Overlay All Zeros

Problem
The Site Overlay report in Google Analytics began showing all links at 0%.

Solution
This particular problem began after adding a "Default page" setting to the website profile. After removing the setting, Site Overlay began working again.

Steps to remove setting:
  1. Click "Analytics Settings"
  2. Under "Website Profiles" click "Edit" under "Actions" column of profile to change
  3. Click "Edit" next to "Main Website Profile Information"
  4. Delete entry for "Default page"
  5. Click "Save Changes" button

How to Create .NET Object From String

Problem
Need to generate an instance of a class dynamically from a string value.

Solution
Use Assembly.CreateInstance Method to create an instance of a type name.
  

Assembly currentAssembly = Assembly.GetExecutingAssembly();

MyClass myClassObjectFromString = null;

try

{

myClassObjectFromString = currentAssembly.CreateInstance("MyNamespace.MyClass") as MyClass;

}

catch

{

}

if (myClassObjectFromString != null)

{

//

}

References
"Assembly.GetExecutingAssembly Method (System.Reflection)." MSDN: Microsoft Development, MSDN Subscriptions, Resources, and More. 23 June 2009 http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getexecutingassembly(VS.80).aspx.

"Assembly.CreateInstance Method (String) (System.Reflection)." MSDN: Microsoft Development, MSDN Subscriptions, Resources, and More. 23 June 2009 http://msdn.microsoft.com/en-us/library/dex1ss7c(VS.80).aspx.

See Also
"How to Convert an ASP.NET Control to String |." CSC - Technical Notes. 23 June 2009 http://csc-technicalnotes.blogspot.com/2009/03/how-to-convert-control-to-html-string.html.

Unable to Disable ASP.NET Themes

Problem
Received the following error on web page that did not require themes:

Using themed css files requires a header control on the page. (e.g. <head runat="server" />).

Setting EnableTheming="false" did not work.

Solution
If themes are not required on page, disable themes with additional attributes:

<%@ Page EnableTheming="false" Theme="" StylesheetTheme="" %>

Note: It is undocumented that you must specify empty attributes Theme and StylesheetTheme.

References
"How to: Disable ASP.NET Themes." MSDN: Microsoft Development, MSDN Subscriptions, Resources, and More. 03 June 2009 http://msdn.microsoft.com/en-us/library/kx3kzht7(VS.80).aspx.

Firefox Tips

Duplicate current tab
Ctrl + click Reload button

Configuration settings
about:config

JavaScript Errors
Tools/Error Console

Profiles Location
%appdata%\Mozilla\Firefox\Profiles

Change number of results in URL bar
Change browser.urlbar.maxRichResults value in about:config.

See "Browser.urlbar.maxRichResults - MozillaZine Knowledge Base." Knowledge Base - MozillaZine Knowledge Base. Web. 16 Sept. 2011. <http://kb.mozillazine.org/Browser.urlbar.maxRichResults>.

Set Ctrl + Tab to go to most recently used (MRU) tab
Note: This is similar to the IE9 setting "Use most recent order when switching tabs with Ctrl+Tab".

Firefox 5
1) Change browser.ctrlTab.previews to true in about:config.

See "Making CTRL+TAB to go to Most Recently Used Tab • mozillaZine Forums." Web. 2 Aug. 2011.
<http://forums.mozillazine.org/viewtopic.php?f=23&t=2136713>.

Close Button on Last Tab Missing in Firefox
Firefox 5
1) Change browser.tabs.closeWindowWithLastTab to false in about:config.
Firefox 3.5
1) Change browser.tabs.closeWindowWithLastTab to false in about:config.
2) Add the following to userChrome.css:
.tabbrowser-tabs[closebuttons="alltabs"] > .tabbrowser-tab > .tab-close-button
{
display: -moz-box !important;
}
.tabbrowser-tabs:not([closebuttons="noclose"]):not([closebuttons="closeatend"]) > .tabbrowser-tab[selected="true"] > .tab-close-button
{
display: -moz-box !important;
}

See: Show Close Button In Last Tab with Firefox 3.5 | Joe Riggs Bloggs
http://joe-riggs.com/blog/2009/07/show-close-button-in-last-tab-with-firefox-3-5/

Updates
2014-04-01 Added "Duplicate current tab"
2011-09-16 Added "Change number of results in URL bar"
2011-08-02 Added "Ctrl + Tab" section.
2011-07-19 Added Firefox 5 "Last Tab Missing" step.

Problem Ejecting USB Mass Storage Device

Problem
Unable to Safely Remove Hardware while trying to remove USB Mass Storage Device - (Drive E:)

Received message:
Problem Ejecting USB Mass Storage Device
The device 'Generic volumne' cannot be stopped right now. Try stopping the device again later.
Solution
Use Sysinternals Process Explorer to find locking process and terminate it.

References
"Problem Ejecting USB Mass Storage Device." Microsoft Help and Support. 25 May 2009
http://support.microsoft.com/kb/555665.

"Process Explorer." Microsoft TechNet: Resources for IT Professionals. 25 May 2009
http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx.

Determine MSDN Library Version

Problem
How to tell which version of MSDN Library is installed.

Solution
Look in Read Me file.







References
"How to tell the version of MSDN Library?" MSDN Social. 18 May 2009
http://social.msdn.microsoft.com/Forums/en-US/devdocs/thread/0d2958f4-e155-48cd-94ea-e667cfc07e32.

KB955706 0x2B33

Problem
Received the following error during Microsoft Update:

The following updates were not installed:
Microsoft SQL Server 2005 Service Pack 3 (KB955706)

Error Code: 0x2B33


Solution
1) Located the error logs after reading Microsoft Discussion (see References below):
C:\Program Files\Microsoft SQL Server\90\Setup Bootstrap\LOG\Hotfix\Summary.txt
C:\Program Files\Microsoft SQL Server\90\Setup Bootstrap\LOG\Hotfix\SQL9_Hotfix_KB955706_sqlrun_sql.msp.log

2) Found this information in Summary.txt:
**********************************************************************************
Products Disqualified & Reason
Product Reason
Analysis Services (MSSQLSERVER) Service was found to be disabled

...

**********************************************************************************
Summary
Service was found to be disabled
Exit Code Returned: 11059

3) Set the following Windows service Startup Type to Manual:
SQL Server Analysis Services (MSSQLSERVER)

4) Reran Microsoft Update successfully

References
"Error Code: 0x2B33 KB960082 Failed in Windows Update." Microsoft Corporation. 03 Apr. 2009
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?&query=KB955706+0x2B33&lang=en&cr=US&guid=&sloc=en-us&dg=microsoft.public.windowsupdate&p=1&tid=2d23c773-f4ec-405c-976c-c444694c6700