Alvin’s Blog

October 5, 2009

IIS – Service account in application pool

Filed under: .NET, IIS — amcbride @ 6:20 pm

1) Service account must be added to the IIS_WPG group
2) Add a new application domain and set the identify to the service account
3) Update the web.config to use trusted connections

March 9, 2009

RegEx: Replace string within a file

Filed under: .NET, RegEx — amcbride @ 11:43 pm

Sample Call

ReplaceInFile(@”x:\setup\P8574.T857402.R45.T107801.CSV”, @”\s{65,}”, System.Environment.NewLine);

 
/// <summary>
/// Replaces text in a file.
/// </summary>
/// <param name=”filePath”>Path of the text file.</param>
/// <param name=”searchText”>Text to search for.</param>
/// <param name=”replaceText”>Text to replace the search text.</param>
static public void ReplaceInFile( string filePath, string searchText, string replaceText )
{
 StreamReader reader = new StreamReader( filePath );
        string content = reader.ReadToEnd();
        reader.Close();

        content = Regex.Replace( content, searchText, replaceText, RegexOptions.Singleline);

        StreamWriter writer = new StreamWriter( filePath );
        writer.Write( content );
        writer.Close();
}

December 1, 2008

VS – Reset skipped packages

Filed under: .NET — amcbride @ 10:54 pm

devenv /resetskippkgs

November 18, 2008

Enterprise Library Data – Retrieving XML from SQL Server

Filed under: .NET — amcbride @ 9:48 pm
Tags: ,

SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand(“usp_GetProjects_XML”);
db.AddInParameter(cmd, “AirID”, SqlDbType.Int, airID);

XmlReader xmlRdr = null;
StringBuilder sbData = new StringBuilder();

try
{
xmlRdr = db.ExecuteXmlReader(cmd);
while (!xmlRdr.EOF)
{
if (xmlRdr.IsStartElement())
{
sbData.Append(xmlRdr.ReadOuterXml());
sbData.Append(Environment.NewLine);
}
}
}
finally
{
if (xmlRdr != null)
{
xmlRdr.Close();
}

// Explicitly close the connection. The connection is not closed
// when the XmlReader is closed.
if (cmd.Connection != null)
{
cmd.Connection.Close();
}
}

return = sbData.ToString();

September 13, 2008

ASPX – CheckBoxList RequiredFieldValidator

Filed under: .NET — amcbride @ 5:14 pm
Tags: ,
<script type=”text/javascript”>
        function ValidateCheckBoxList(source, args)
        {
            var chkList = document.getElementById(‘<%= lbChangeType.ClientID %>’);
            var chkLista= chkList.getElementsByTagName(“input”);
           
            for(var i=0;i<chkLista.length;i++)
            {  
                if(chkLista[i].checked)
                {
                    args.IsValid = true;
                    return;
                }
            }
           
            args.IsValid = false;
        } 
        </script>

June 27, 2008

.NET;Security – Encrypt identity of web.config

Filed under: .NET — amcbride @ 4:24 pm

aspnet_regiis -pef “system.web/identity” “C:\Sites\IntranetSite” -prov “DataProtectionConfigurationProvider”

Decrypt

aspnet_regiis -pdf “system.web/identity” “C:\FOLDER_SHARE\VS 2008\ApprovalRunner”

February 25, 2008

.NET – C# calling optional parameters (Win32 API)

Filed under: .NET — amcbride @ 9:51 pm

Use System.Reflection.Missing.Value for missing parameter.

March 6, 2007

Vista – Debugging with Visual Studio 2005

Filed under: .NET, Vista — amcbride @ 4:56 am

 Steps that I had to make in order to get this to work.

 1. Install IIS 7

http://weblogs.asp.net/scottgu/archive/2006/09/19/Tip_2F00_Trick_3A00_-Using-IIS7-on-Vista-with-VS-2005.aspx

2. (64 bit) Install “Visual Studio 2005 Remote Debugger

DVD\vs\Remote Debugger\x64

3.  Switched from the DefaultAppPool to ”Classic .NET AppPool” in Advanced Settings

March 5, 2007

.NET – Allowing dynamic controls with viewstate

Filed under: .NET — amcbride @ 12:28 am

<asp:PlaceHolder runat=”server” ID=”panel1″>

</asp:PlaceHolder>

<asp:Button id=”Button1″ runat=”server” Text=”Submit”></asp:Button>

********************************

Partial Class Default2

Inherits System.Web.UI.Page

‘ Added by hand; will create instance in OnInit.

Public TextBox1 As System.Web.UI.WebControls.TextBox
 

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init

‘ Create dynamic controls here.

TextBox1 = New TextBox()

panel1.Controls.Add(TextBox1)

End Sub
 

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not IsPostBack Then

‘ Set the initial properties for the text boxes.

TextBox1.Text = “TextBox1″

End If

End Sub

End Class

Blog at WordPress.com.