ERROR
It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS
Solution
Remove web.config from the backup folder created by Visual Studio.
Friday, June 15, 2007
Changing the Configuration database server in MOSS 2007
To change the configration database server in MOSS 2007 do the following
1. Shutdown the servers in the farm
2. Copy all the configuration database to the new database server
3. Turn on the servers and execute stsadm -o renameserver -olservername -newservername
4. You should reboot the server
5. Execute these steps on all the servers in the farm
1. Shutdown the servers in the farm
2. Copy all the configuration database to the new database server
3. Turn on the servers and execute stsadm -o renameserver -olservername
4. You should reboot the server
5. Execute these steps on all the servers in the farm
Thursday, March 30, 2006
Parsing HTML.
In my recent project, I had a requirement to parse HTML documents. I was debating between using the web browser control which gives the HTML as a DOM and HttpWebRequest where I had to do all the parsing. A quick search on google took me to Html Agility Pack.
This is a HTML parser that allows you to parse "out of the web" HTML files and creates a DOM. This supports plain XPATH or XSLT.
This is a HTML parser that allows you to parse "out of the web" HTML files and creates a DOM. This supports plain XPATH or XSLT.
Difference between Directory.GetFiles and windows explorer sorting numeric files.
The .NET Sytem.IO.Directory.GetFiles class returns the files sorted in alphabetic order whereas Windows Explorer sorts them in numeric order. For e.g
If you have access to the source then you can pass the string array returned from Directory.GetFiles to Array's Sort(Array, IComparer) method to sort it in numeric order.
If you do not have access to the source then you can modify the registry as below for explorer to sort using the alphabetic order. Restart explorer for the changes to take effect.
For current user:[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
For the System:
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
Value Name: NoStrCmpLogical
Type: REG_DWORD
Value:1
Disclaimer: Modifying the registry can cause serious problems that may require you to reinstall your operating system. Use the information provided at your own risk.
| In Directory.GetFiles | In Explorer | |
| 04.html | 1.html | |
| 040.html | 3.html | |
| 05.html | 04.html | |
| 1.html | 05.html | |
| 10.html | 10.html | |
| 3.html | 040.html |
If you have access to the source then you can pass the string array returned from Directory.GetFiles to Array's Sort(Array, IComparer) method to sort it in numeric order.
If you do not have access to the source then you can modify the registry as below for explorer to sort using the alphabetic order. Restart explorer for the changes to take effect.
For current user:[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
For the System:
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
Value Name: NoStrCmpLogical
Type: REG_DWORD
Value:1
Disclaimer: Modifying the registry can cause serious problems that may require you to reinstall your operating system. Use the information provided at your own risk.
Tuesday, November 22, 2005
Hidden MessageBox and VSTO
When trying to display a Message box from VSTO code, the message box is some times hidden in the background. MessageBox's Show method takes a "owner" parameter of type IWin32Window, this makes the Message box to be displayed in front of the IWin32Window passed. Below is a code snippet from gotdotnet site to get the IWin32Window of the foreground window.
// Stephen Toub
// stoub@microsoft.com
//
// ActiveWindow.cs v1.0.0
// 8/28/02
//
// Implements IWin32Window where Handle returns the handle of the system's foreground window.
// Can be used with MessageBox to display the box in front of the active window, such as:
// MessageBox.Show(ActiveWindow.Active, "Hello, World!");
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace Toub.Windows.Forms
{
///Used to get an IWin32Window for the active window.
public class ActiveWindow : IWin32Window
{
#region Private Members
///Static instance to use for factory pattern.
private static ActiveWindow _window = new ActiveWindow();
#endregion
#region Construction
///Prevent external instantiation.
private ActiveWindow() {}
#endregion
#region Public Properties
///Gets an IWin32Window for the active window.
public static IWin32Window Active { get { return _window; } }
#endregion
#region Private Functions
///Finds the frontmost window using the Win32 API.
[DllImport("user32.dll")]
private static extern int GetForegroundWindow();
///Gets a handle to the active window.
System.IntPtr IWin32Window.Handle
{
get { return new System.IntPtr(GetForegroundWindow()); }
}
#endregion
}
}
// Stephen Toub
// stoub@microsoft.com
//
// ActiveWindow.cs v1.0.0
// 8/28/02
//
// Implements IWin32Window where Handle returns the handle of the system's foreground window.
// Can be used with MessageBox to display the box in front of the active window, such as:
// MessageBox.Show(ActiveWindow.Active, "Hello, World!");
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace Toub.Windows.Forms
{
///
public class ActiveWindow : IWin32Window
{
#region Private Members
///
private static ActiveWindow _window = new ActiveWindow();
#endregion
#region Construction
///
private ActiveWindow() {}
#endregion
#region Public Properties
///
public static IWin32Window Active { get { return _window; } }
#endregion
#region Private Functions
///
[DllImport("user32.dll")]
private static extern int GetForegroundWindow();
///
System.IntPtr IWin32Window.Handle
{
get { return new System.IntPtr(GetForegroundWindow()); }
}
#endregion
}
}
Tuesday, November 08, 2005
How to Retrieve XML data from MS Word form fields using VSTO.
MS word has this cool feature where you can attach an XML schema to the document and tag the form fields with XML elements in the schema. When you save the document as XML, the form field values are stored as XML data. Unfortunately saving XML data does not work with Check box and Drop down form fields. So, if you need to save the data from Check box and Drop down form fields you have to walk through all the XML nodes and retrive the data. Below is a C# code snippet to walk through the XML nodes and write it as XML.
private string BuildWordDocumentXmlData(XMLNode xmlNode)
{
object oRef = 1;
object missing = Missing.Value;
Range range;
StringBuilder xmlString = new StringBuilder();
xmlString.Append("");
if(!xmlNode.HasChildNodes)
{
xmlString.Append("<" + xmlNode.BaseName + ">");
range = xmlNode.Range;
if (range.FormFields.Count > 0)
{
FormField formField = range.FormFields.get_Item(ref oRef);
if (formField.Type == WdFieldType.wdFieldFormCheckBox)
{
if (formField.Result.CompareTo("1") == 0)
{
xmlString.Append("true");
}
else
{
xmlString.Append("false");
}
}
else if (formField.Type == WdFieldType.wdFieldFormTextInput)
{
if (formField.Result != null)
{
xmlString.Append(formField.Result);
}
}
}
else
{
xmlString.Append(xmlNode.Text);
}
xmlString.Append("" + xmlNode.BaseName + ">");
}
else
{
string returnString;
xmlString.Append("<" + xmlNode.BaseName + ">\n");
foreach(XMLNode childXmlNode in xmlNode.ChildNodes)
{
returnString = BuildWordDocumentXmlData(childXmlNode);
xmlString.Append(returnString + "\n");
}
xmlString.Append("" + xmlNode.BaseName + ">");
}
return xmlString.ToString();
}
public void SaveWordDocumentXmlData(string xmlFileName)
{
Application.ScreenUpdating = false;
string xml;
try
{
xml = BuildWordDocumentXmlData(ActiveDocument.XMLNodes[1]);
using (StreamWriter sw = new StreamWriter(xmlFileName))
{
sw.Write(xml);
}
}
catch(Exception exp)
{
Trace.WriteLine(exp.ToString());
}
Application.ScreenUpdating = true;
}
private string BuildWordDocumentXmlData(XMLNode xmlNode)
{
object oRef = 1;
object missing = Missing.Value;
Range range;
StringBuilder xmlString = new StringBuilder();
xmlString.Append("");
if(!xmlNode.HasChildNodes)
{
xmlString.Append("<" + xmlNode.BaseName + ">");
range = xmlNode.Range;
if (range.FormFields.Count > 0)
{
FormField formField = range.FormFields.get_Item(ref oRef);
if (formField.Type == WdFieldType.wdFieldFormCheckBox)
{
if (formField.Result.CompareTo("1") == 0)
{
xmlString.Append("true");
}
else
{
xmlString.Append("false");
}
}
else if (formField.Type == WdFieldType.wdFieldFormTextInput)
{
if (formField.Result != null)
{
xmlString.Append(formField.Result);
}
}
}
else
{
xmlString.Append(xmlNode.Text);
}
xmlString.Append("" + xmlNode.BaseName + ">");
}
else
{
string returnString;
xmlString.Append("<" + xmlNode.BaseName + ">\n");
foreach(XMLNode childXmlNode in xmlNode.ChildNodes)
{
returnString = BuildWordDocumentXmlData(childXmlNode);
xmlString.Append(returnString + "\n");
}
xmlString.Append("" + xmlNode.BaseName + ">");
}
return xmlString.ToString();
}
public void SaveWordDocumentXmlData(string xmlFileName)
{
Application.ScreenUpdating = false;
string xml;
try
{
xml = BuildWordDocumentXmlData(ActiveDocument.XMLNodes[1]);
using (StreamWriter sw = new StreamWriter(xmlFileName))
{
sw.Write(xml);
}
}
catch(Exception exp)
{
Trace.WriteLine(exp.ToString());
}
Application.ScreenUpdating = true;
}
Friday, October 21, 2005
Subscribe to:
Posts (Atom)