A personal repository of technical notes. - CSC

Windows Explorer Command-Line Options for Windows XP

BAT file code
@echo off
start %SystemRoot%\explorer.exe /n,/root, "C:\MyFolder"


References
"Explorer.exe Command-Line Options for Windows XP." Microsoft Support. Web. 24 Dec. 2009. <http://support.microsoft.com/kb/314853>.

The options that you can use with Explorer.exe are /n, /e, /root (plus an object), and /select (plus an object).

Option            Function
----------------------------------------------------------------------
/n Opens a new single-pane window for the default
selection. This is usually the root of the drive that
Windows is installed on. If the window is already
open, a duplicate opens.

/e Opens Windows Explorer in its default view.

/root,<object> Opens a window view of the specified object.

/select,<object> Opens a window view with the specified folder, file,
or program selected.

CSS Nested Lists

  

<ol style="list-style-type: decimal;">

<li>aaa

<ol style="list-style-type: lower-alpha;">

<li>aaa</li>

<li>bbb

<ol style="list-style-type: lower-roman;">

<li>aaa</li>

<li>bbb</li>

<li>ccc</li>

</ol>

</li>

<li>ccc</li>

</ol>

</li>

<li>bbb</li>

<li>ccc</li>

</ol>

  1. aaa
    1. aaa
    2. bbb
      1. aaa
      2. bbb
      3. ccc
    3. ccc
  2. bbb
  3. ccc

How to Debug JavaScript

Problem
Debugging JavaScript in Firefox
Debugging JavaScript in IE

Solution for Debugging JavaScript in Firefox

Firebug Method:
  1. Open page to debug in Firefox
  2. Start Firebug
  3. Click on the "Script" tab on top of Firebug pane
  4. Assign break points and step through code as you would with VS2005
Solution for Debugging JavaScript in IE6

Debugger line method:
  1. IE: Tools/Internet Options/Advanced Tab/Uncheck "Disable Script Debugging"
  2. VS: Add following line to JavaScript code:
    debugger;
  3. Add breakpoint to line above
  4. Remove line above after debugging complete
VS2005 Attach to Process Method:
  1. IE: Tools/Internet Options/Advanced Tab/Uncheck "Disable Script Debugging"
  2. VS: Solution Explorer/Right-Click .ASPX/View in Browser
  3. VS: Debug/Attach to Process...
    1. Attach to: Click Select.../Check Script
    2. Available Processes/Select iexplore.exe of .ASPX
    3. Click Attach
  4. VS: Debug/Windows/Script Explorer
  5. VS Script Explorer: Double-Click page to open scipt for setting break points

Visual Studio Documentation Comments for C#

Tip
Include XML Documentation Comments in C# code:

<c>
<code>
<example>
<exception>
<include>
<list>
<para>
<param>
<paramref>
<permission>
<remarks>
<returns>
<see>
<seealso>
<summary>
<typeparam>
<typeparamref>
<value>

References
"Recommended Tags for Documentation Comments (C#)." MSDN: Microsoft Development, MSDN Subscriptions, Resources, and More. Web. 02 Dec. 2009.
<http://msdn.microsoft.com/en-us/library/5ast78ax%28VS.80,loband%29.aspx>.

SQL Server Management Studio Default My Projects Location

Problem
Need to change default location of My Projects folder in SSMS

Solution for SSMS 2008
Had to add a new registry entry "VisualStudioProjectsLocation" of type "Expandable String Value" (REG_EXPAND_SZ) at
HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server\100\Tools\Shell

Solution That Worked for SSMS 2005
Modify registry entry "VisualStudioProjectsLocation" at
HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server\90\Tools\Shell

References for Solution That Worked for SSMS 2005
"How to change the default ‘My Projects’ location in SQL Server Management Studio «." Pepper's Perspective. Web. 15 Sept. 2009. <http://p3john.wordpress.com/2009/08/11/how-to-change-the-default-my-projects-location-in-sql-server-management-studio/>.


Solution That Did Not Work for SSMS 2005
This solution did not work for me. After saving vssettings file, SSMS regenerated the settings file with the old values on the next start after displaying message "Microsoft SQL Server Management Studio is configuring the environment for first time use. This might take a few minutes."

Manually modify SSMS *.vssettings XML file at location:
\My Documents\SQL Server Management Studio\Settings\

See entry:
<PropertyValue name="ProjectsLocation">%vsspv_visualstudio_dir%\Projects</PropertyValue>
References for Solution That Did Not Work for SSMS 2005
"Changing the My Projects folder location (and other settings) in SSMS :." Visual Studio Hacks. Web. 15 Sept. 2009.
<http://visualstudiohacks.com/tips/options/changing-the-my-projects-folder-location-and-other-settings-in-ssms/>.

Updates
2011-07-05 Added SSMS 2008 references.

INSERT failed because the following SET options have incorrect settings: 'ARITHABORT'.

Problem

Received the following error while performing CREATE Procedure from Visual Studio 2005 after setting up a DDL trigger for database auditing in a SQL Server 2005 database.
INSERT failed because the following SET options have incorrect settings: 'ARITHABORT'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or query notifications and/or xml data type methods.

Solution 1

Added the following line to the DDL auditing database trigger:

SET ARITHABORT ON


Solution 1 References

"Database DDL trigger." Community Bookmarks - MSDN. Web. 19 Aug. 2009.
http://social.msdn.microsoft.com/Forums/en-US/sqlreplication/thread/8333dc82-7390-4145-8081-74d9330938dd.

"SET ARITHABORT (Transact-SQL)." MSDN: Microsoft Development, MSDN Subscriptions, Resources, and More. Web. 19 Aug. 2009.
http://msdn.microsoft.com/en-us/library/ms190306%28SQL.90%29.aspx.

"Behavior When ARITHABORT and ARITHIGNORE Are Set to ON." MSDN: Microsoft Development, MSDN Subscriptions, Resources, and More. Web. 19 Aug. 2009.
http://msdn.microsoft.com/en-us/library/ms189118%28SQL.90%29.aspx.


Solution 2

Found that the database that was throwing the error was configured to be compatible with an older version of SQL Server. Setting the database to be compatible with SQL Server 2005 also corrected the problem.

Solutin 2 References

"Reorg failing - SELECT failed because the following SET options have incorrect settings: 'ARITHABORT'" Community Bookmarks - MSDN. Web. 17 Aug. 2009.
http://social.msdn.microsoft.com/Forums/en-US/sqldatabaseengine/thread/41bf9b3a-ee25-4dde-bf6f-ab1a8d59ea6b.

"Sp_dbcmptlevel (Transact-SQL)." MSDN: Microsoft Development, MSDN Subscriptions, Resources, and More. Web. 17 Aug. 2009.
http://msdn.microsoft.com/en-us/library/ms178653(SQL.90).aspx.

Disable Try Catch Block During Debugging

Problem
Would like to see full errors during debugging process without having to comment out try-catch blocks.

Solution
Note: This was tested in VS2005, VS2013.
Set Visual Studio to always break when an exception is thrown during debug.
  1. Select menu Debug/Exceptions...
  2. Check the box labeled "Thrown" next to "Common Language Runtime Exceptions".
References
"Exception Handling (Debugging)." MSDN: Microsoft Development, MSDN Subscriptions, Resources, and More. Web. 31 July 2009. http://msdn.microsoft.com/en-us/library/x85tt0dd(VS.80).aspx.

"How to: Break When an Exception is Thrown." MSDN: Microsoft Development, MSDN Subscriptions, Resources, and More. Web. 31 July 2009. http://msdn.microsoft.com/en-us/library/d14azbfh(VS.80).aspx.

Updates
2014-09-18 Confirmed works in VS2013.

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

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

Visual Studio Remove "Find and Replace" "Find In Files" "Look In" MRU Entries

Problem
Need to remove obsolete items from most recently used (MRU) Find items in Visual Studio.

Solution
The entries are located at this registry location:
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\ {Visual Studio Version} \Find

References
None

Xml.DocumentSource Will Not Load With Physical Path

Problem
ASP.NET Xml control will not load with physical path when XML file is not part of website. The following error is thrown:

Server Error System.Web.HttpException: 'c:\MyFolder\MyFile.xml' is a physical path.

Property System.Web.UI.WebControls.Xml.DocumentSource may not be a physical path to the requested XML file. It must be a virtual path that is a relative or root relative URL.

Solution
Tested on .NET Framework version 1.1.

1) Instantiate an XmlDocument using physical path.
2) Assign XmlDocument to Xml control

Example using a physical path:

<asp:xml id="xmlControl" transformsource="style.xslt" runat="server"></asp:xml>

...

protected System.Web.UI.WebControls.Xml xmlControl;

System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.Load("C:\MyFolder\MyFile.xml");

xmlControl.Document = xmlDoc;


Example using a website path:

<asp:xml id="xmlControl" transformsource="style.xslt" runat="server"></asp:xml>

...

protected System.Web.UI.WebControls.Xml xmlControl;

xmlControl.DocumentSource = "/MyWebSiteFolder/MyXml.xml";


References
"Xml Class." MSDN: Microsoft Development, MSDN Subscriptions, Resources, and More. 20 Feb. 2009 http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.xml(VS.71).aspx

"XmlDocument Class." MSDN: Microsoft Development, MSDN Subscriptions, Resources, and More. 20 Feb. 2009 http://msdn.microsoft.com/en-us/library/system.xml.xmldocument(VS.71).aspx

Make Property or Class Obsolete

Problem
Need to make class property obsolete so developers will not use it.

Solution
Set property to "obsolete" in code to cause a compile warning or error:
 [System.Obsolete("Deprecated: Don't use OldWay; use NewWay instead", true)]
public string Xxx
{
get
set
}
References
"Obsolete (C#)." MSDN: Microsoft Development, MSDN Subscriptions, Resources, and More. 18 Feb. 2009
http://msdn.microsoft.com/en-us/library/22kk2b44(VS.80).aspx.

Remove Connections from MRU of Visual Studio 2005 Copy Web Site Tool

Problem
Need to remove obsolete connections from most recently used (MRU) list of Copy Web Site Tool.

Solution

To remove a connection to a remote site that still exists:
1. From the Connect to list, select the connection that you want to remove.
2. Click the Disconnect from currently selected remote site button.
(MSDN)

To remove a connection to a remote site that no longer exists, edit contents of:
C:\Documents and Settings\[user name]\Local Settings\Application Data\Microsoft\WebsiteCache\[Web Site Name]\PublishState.xml

Remove obsolete <RemoteSite> sections and corresponding <PublishStatus> sections.

References
"How to: Copy Web Site Files with the Copy Web Site Tool." MSDN: Microsoft Developer Network. 12 Feb. 2009
http://msdn.microsoft.com/en-us/library/c95809c0(VS.80).aspx.

"Copy Web Site - how to remove connections from the list - ng.asp-net-forum.visual_web_developer_2005_express - error problem solve @CodeVerge." CodeVerge.Net - error problem solve @CodeVerge. 12 Feb. 2009
http://www.codeverge.net/ng.asp-net-forum.visual_web_developer_2005_express/copy-web-site-how-to-remove-connections-from-the-list.

"Re: How to remove a Connection from Copy Web Site list?" Tech-Archive.net: The source for usenet news. 12 Feb. 2009
http://www.tech-archive.net/Archive/VisualStudio/microsoft.public.vsnet.general/2007-06/msg00003.html.

Debug Class Library Apart From ASP.NET Solution

Steps to Debug a Class Library That is Not Part of a Visual Studio ASP.NET Solution

Prepare Class Library
- Open class library in Visual Studio
- Build class library in debug mode.
- Manually copy new debug DLLs from bin\debug folder of class library to bin folder of ASP.NET application that is using this class library
- Run web site in browser to rebuild with new dlls

Start Debug Session
- Set breakpoints in code of class library
- Select menu item Debug/Attach to Process...
- Transport: Default
- Attach to/Select...: Automatically determine the type of code to debug
- OK
- Available Processes:
    (If using IIS 6) Select aspnet_wp.exe
    (If using IIS 7) Check "Show processes from all users", check "Show process in all sessions", select w3wp.exe
- Note: There may be more than one. Hold mouse over each and select appropriate version.
- Attach

NOTE: if error, "EXECUTE permission denied on object 'sp_sdidebug', database 'master', owner 'dbo'."
-May "Attach to:" "Managed Code" instead of "Automatic: T-SQL code, Managed code".

NOTE: If error, "The breakpoint will not currently be hit. The source code is different from the original version."
-Need to get newer DLLs into web application. Redo steps under "Prepare Class Library"

NOTE: If error, "The breakpoint will not currently be hit. No symbols have been laoded for this document."
-Make sure "Attach to:" is set to one of the appropriate values listed above.
-Make sure class library was built in debug mode. See "Prepare Class Library" above.
-Open or refresh web page in which you are testing class library to rebuild site using new DLLs. See "Prepare Class Library" above.

Updates
2012-08-27 Added IIS 6 and IIS 7 notes.

Free Citation Web Sites

Problem
Need to accurately cite quoted sources.

Solutions
Use free cite making website

BibMe
Welcome to BibMe! The fully automatic bibliography maker that auto-fills. It's the easiest way to build a works cited page. And it's free.

"BibMe: Fast & Easy Bibliography Maker - MLA, APA, Chicago, Turabian - Free." BibMe: Fast & Easy Bibliography Maker - MLA, APA, Chicago, Turabian - Free. N.p., n.d. Web. 2 Aug. 2011.
<http://www.bibme.org/>.

EasyBib Free Bibliography Maker
The fastest way to create accurate, comprehensive works cited lists. 183,320,718 citations made to date. Now with Autocite: Cite books with just an ISBN number, and websites with just a URL.

EasyBib: Free Bibliography Maker - MLA, APA, Chicago Citation Styles. Web. 02 Aug. 2011.
<http://www.easybib.com>.

See Also
"Kinds of Sources and How to Cite Them | Using Sources | Writing at Yale | The Writing Center | Yale College." Yale University. Web. 22 Jan. 2010.
<http://www.yale.edu/bass/writing/sources/kinds/index.html>.

Updates
2011-08-02 Added BibMe reference.

ConfigurationManager.GetSection() as NameValueCollection Example

Problem
Need a custom AppSettings section in config file.

Solution
Create a custom section in config file based upon AppSettingsSection. Then use NameValueCollection to handle settings. See ConfigurationManager GetSection example below.

Note: Tested in .NET 4.0 and 2.0. If using 2.0, change the version number of type in config from 4 to 2.

<?xml version="1.0"?>
<configuration>
       <configSections>
              <sectionGroup name="customAppSettingsGroup">
                     <section name="customAppSettingsAAA" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
                     <section name="customAppSettingsBBB" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
                     <section name="customAppSettingsCCC" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
              </sectionGroup>
       </configSections>
       <customAppSettingsGroup>
              <customAppSettingsAAA>
                     <add key="KeyOneAAA" value="ValueOneAAA"/>
                     <add key="KeyTwoAAA" value="ValueTwoAAA"/>
                     <add key="KeyThreeAAA" value="ValueThreeAAA"/>
              </customAppSettingsAAA>
              <customAppSettingsBBB>
                     <add key="KeyOneBBB" value="ValueOneBBB"/>
                     <add key="KeyTwoBBB" value="ValueTwoBBB"/>
                     <add key="KeyThreeBBB" value="ValueThreeBBB"/>
              </customAppSettingsBBB>
              <customAppSettingsCCC>
                     <add key="KeyOneCCC" value="ValueOneCCC"/>
                     <add key="KeyTwoCCC" value="ValueTwoCCC"/>
                     <add key="KeyThreeCCC" value="ValueThreeCCC"/>
              </customAppSettingsCCC>
       </customAppSettingsGroup>
</configuration>

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Text;
using System.Web.Configuration;

public partial class ProofOfConcept_Configuration_Default : System.Web.UI.Page
{
       protected void Page_Load(object sender, EventArgs e)
       {
              StringBuilder outputStringBuilder = new StringBuilder();

              // EXAMPLE 1: Retrieve 1 custom appsettings section.

              // ConfigurationManager.GetSection() as NameValueCollection example
              // Create a custom AppSettings section in config file
              NameValueCollection settingsAAA = ConfigurationManager.GetSection("customAppSettingsGroup/customAppSettingsAAA") as NameValueCollection;
              if (settingsAAA != null && settingsAAA.Count > 0)
              {
                     // Individual setting
                     outputStringBuilder.AppendLine("Individual setting ----------");
                     outputStringBuilder.AppendLine(settingsAAA["KeyTwoAAA"]);

                     // All settings Values in section
                     outputStringBuilder.AppendLine("All settings values in section ----------");
                     foreach (string key in settingsAAA.AllKeys)
                     {
                           outputStringBuilder.AppendLine(settingsAAA[key]);
                     }

                     // All settings' Keys and Values to GridView via Dictionary.
                     Dictionary<string, string> outputDictionary = new Dictionary<string, string>(settingsAAA.Count);
                     outputDictionary.Add("[Dictionary to GridView]", "[Example]");
                     foreach (string key in settingsAAA.AllKeys)
                     {
                           outputDictionary.Add(key, settingsAAA[key]);
                     }
                     MainGridView.DataSource = outputDictionary;
                     MainGridView.DataBind();
              }

              // EXAMPLE 2: Put multiple custom appsettings sections into a single Dictionary collection.

              Dictionary<string, NameValueCollection> settingsDictionary = new Dictionary<string, NameValueCollection>();

              settingsDictionary.Add("customAppSettingsAAA", ConfigurationManager.GetSection("customAppSettingsGroup/customAppSettingsAAA") as NameValueCollection);
              settingsDictionary.Add("customAppSettingsBBB", ConfigurationManager.GetSection("customAppSettingsGroup/customAppSettingsBBB") as NameValueCollection);
              settingsDictionary.Add("customAppSettingsCCC", ConfigurationManager.GetSection("customAppSettingsGroup/customAppSettingsCCC") as NameValueCollection);

              outputStringBuilder.AppendLine("Dictionary items ----------");
              outputStringBuilder.AppendLine(settingsDictionary["customAppSettingsAAA"]["KeyTwoAAA"]);
              outputStringBuilder.AppendLine(settingsDictionary["customAppSettingsBBB"]["KeyOneBBB"]);
              outputStringBuilder.AppendLine(settingsDictionary["customAppSettingsCCC"]["KeyThreeCCC"]);

              // EXAMPLE 3: Loop through each setting of each section in a group

              Configuration webConfig = WebConfigurationManager.OpenWebConfiguration("~/ProofOfConcept/Configuration"); // NOTE: MUST INCLUDE FULL PATH TO SUBFOLDER OF WEB.CONFIG IF NECESSARY
              ConfigurationSectionGroup myGroup = webConfig.GetSectionGroup("customAppSettingsGroup");
              outputStringBuilder.AppendLine("Loop through entire group ----------");

              foreach (ConfigurationSection section in myGroup.Sections)
              {
                     outputStringBuilder.AppendLine(section.SectionInformation.SectionName);
                     NameValueCollection settings = ConfigurationManager.GetSection(section.SectionInformation.SectionName) as NameValueCollection;
                     foreach (string key in settings)
                     {
                           outputStringBuilder.AppendLine(String.Format(" {0} = {1}", key, settings[key]));
                     }
              }

              MainLiteral.Text = outputStringBuilder.ToString();
       }
}

Sample Output

Individual setting ----------
ValueTwoAAA
All settings values in section ----------
ValueOneAAA
ValueTwoAAA
ValueThreeAAA
Dictionary items ----------
ValueTwoAAA
ValueOneBBB
ValueThreeCCC
Loop through entire group ----------
customAppSettingsGroup/customAppSettingsCCC
 KeyOneCCC = ValueOneCCC
 KeyTwoCCC = ValueTwoCCC
 KeyThreeCCC = ValueThreeCCC
customAppSettingsGroup/customAppSettingsAAA
 KeyOneAAA = ValueOneAAA
 KeyTwoAAA = ValueTwoAAA
 KeyThreeAAA = ValueThreeAAA
customAppSettingsGroup/customAppSettingsBBB
 KeyOneBBB = ValueOneBBB
 KeyTwoBBB = ValueTwoBBB
 KeyThreeBBB = ValueThreeBBB

KeyValue
[Dictionary to GridView][Example]
KeyOneAAAValueOneAAA
KeyTwoAAAValueTwoAAA
KeyThreeAAAValueThreeAAA


Updates
2020-04-01 Added example 3: Loop through each setting of each section in a group
2014-05-23 Added example: All settings' Keys and Values to GridView via Dictionary.
2013-12-05 Added Example 2.
2013-11-11 Updated example code.

Blog Archive