A personal repository of technical notes. - CSC

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

How to Convert an ASP.NET Control to String

Problem
Need to generate an HTML string from an ASP.NET web control created in code-behind without rendering it on the web page.

Solution
Use the control's RenderControl() method with a StringWriter to generate the HTML.
  

// Code sample of a utility method to convert a control to an HTML string

public static string RenderControlToString(Control control)

{

string renderedControl = null;

if (control != null)

{

using (StringWriter tempStringWriter = new StringWriter())

{

using (HtmlTextWriter tempHtmlTextWriter = new HtmlTextWriter(tempStringWriter))

{

control.RenderControl(tempHtmlTextWriter);

renderedControl = tempStringWriter.ToString();

tempHtmlTextWriter.Close();

}

tempStringWriter.Close();

}

}

return renderedControl;

}

// Test Utility Method

private void TestRenderControlToString()

{

HyperLink testHyperLink = new HyperLink();

testHyperLink.NavigateUrl = "/MyWebFolder/Default.aspx";

testHyperLink.Text = "Hyper Link Value";

testHyperLink.Target = "_blank";

string renderedControl = Utility.RenderControlToString(testHyperLink);

Response.Write(Server.HtmlEncode(renderedControl));

Response.Write(renderedControl);

}


References
"Control.RenderControl Method (System.Web.UI)." MSDN: Microsoft Development, MSDN Subscriptions, Resources, and More. 27 Mar. 2009
http://msdn.microsoft.com/en-us/library/system.web.ui.control.rendercontrol(VS.80).aspx.

"StringWriter Class (System.IO)." MSDN: Microsoft Development, MSDN Subscriptions, Resources, and More. 27 Mar. 2009
http://msdn.microsoft.com/en-us/library/system.io.stringwriter(VS.80).aspx.

SQL CASE Examples

-- --------------------------------------------------
-- Simple CASE function:
-- --------------------------------------------------
CASE input_expression
      WHEN when_expression THEN result_expression
      ELSE else_result_expression
END

-- --------------------------------------------------
-- Searched CASE function:
-- --------------------------------------------------
CASE
      WHEN Boolean_expression THEN result_expression
      ELSE else_result_expression
END

-- CASE with multiple values tested
CASE
      WHEN t1.Column1 IN(103,109,83) THEN 'PassedTest'
      ELSE NULL
END

-- --------------------------------------------------
-- SELECT calculation
-- --------------------------------------------------
SELECT
(2 *
      CASE @RequestedSchedule
            WHEN 'M' THEN @intMonthly
            WHEN 'Q' THEN @intQuarterly
            ELSE 'Unexpected Value in RequestedSchedule: ' + @RequestedSchedule
      END
)

-- --------------------------------------------------
-- SELECT CASE EXISTS
-- --------------------------------------------------
SELECT
      a.Column01
      ,a.Column02
      ,CASE WHEN EXISTS (SELECT z.Column05 FROM TableZ AS z WHERE zColumn06 = a.Column01)
            THEN 'Exists'
            ELSE 'Not Exists'
      END
FROM
      TableA AS a

-- --------------------------------------------------
-- Set selection mode based upon passed parameters
-- --------------------------------------------------
DECLARE
      @currentSelectionMode int
      ,@selectionModeByAAA int
      ,@selectionModeByBBB int
SELECT
      @selectionModeByAAA = 1
      ,@selectionModeByBBB = 2

SELECT @currentSelectionMode =
      CASE
            WHEN @passedValue01 IS NOT NULL THEN @selectionModeByAAA
            WHEN @passedValue02 IS NOT NULL THEN @selectionModeByBBB
            ELSE 0
      END

IF (@currentSelectionMode = 0)
BEGIN
      RAISERROR('No valid selection criteria was passed.', 11, 1)
      -- Ths first number, severity, is the user-defined severity level associated with this message.
      -- Severity levels from 0 through 18 can be specified by any user.
      -- NOTE: Must be >= 11 in order to throw an error in C#
      RETURN -1
END

WRT54G Connection To Motorola Modem

Problem
Unable to connect through to internet from Linksys WRT54G router to Motorola 2110-02-1002 DSL modem.

Solution
Had to change IP address of router from 192.168.1.1 to 192.168.2.1 even though modem IP address is 192.168.1.254

Was able to keep PPPoE on modem and did not have to enable PPPoE on the router.

References
"Setting-Up a Router with DSL Internet Service" Linksys Easy Answers (Page 1 of 121). 19 Mar. 2009
http://linksys.custhelp.com/cgi-bin/linksys.cfg/php/enduser/std_adp.php?p_faqid=3687&lid=3973237401B07.

How to Convert "File System" web site to "HTTP" web site in VS2005

Problem
Need to convert "File System" web site to "HTTP" web site in Visual Studio 2005.

For sample reason to convert, see "Server-Side Include "Failed to map the path"" CSC - Technical Notes. 24 Feb. 2009
http://csc-technicalnotes.blogspot.com/2008/12/server-side-include-virtual-failed-to.html.

Solution
1) Set up application in IIS for web site
- Directory: Select existing File System web site folder in solution

2) In IIS, set the directory to the existing File System web site folder in solution

3) Remove File System web site from solution
- Right-click File System web site in Solution Explorer
- Remove

4) Add HTTP web site to solution
- Solution Explorer/Right-click Solution/Add/Existing Web Site
- Add Existing Web Site Dialog/Click "Local IIS"
- Under "Local Internet Information Server", select virtual folder created above
- Open

5) Bind web site code to old VSS location
- VS2005/File/Source Control/Change Source Control
- Select HTTP web site from list
- Click "Bind" button
- Log into VSS if necessary
- VSS/Select project folder of old File System web site
- OK
- If Status = "Valid"
- OK
- Select "Allow these files to be replaced by their server versions"
- OK
- Done

- If Status = "Invalid",
- Cancel
- "Microsoft Visual Studio needs to reopen source control database connections for projects in the solution. Your source control provider may prompt for your credentials."
- OK

- NOTE: Performing 1 or more of the following tasks may enable the binding to be "Valid":
1: [This alone should work] Close VS and delete solution *.suo file.
2: Check one file from new web site into VSS. This will be created in a VSS default location.
3: Delete all files named "vssver.scc" in web site folders and sub-folders from Windows Explorer
- Retry steps under "Bind web site code to old VSS location"
- Delete project and file from VSS that was created during step "2:" above.
- This error may be thrown:
 Unexpected error encountered. It is recommended that you restart the application as soon as possible.
Error: Unspecified error
File: vsee\pkgs\vssprovider\abstractionlayerdispatcher.cpp
Line number: 4720