Wednesday, September 24, 2008

Here is an example of Asp.NET Web page - "complete" zip code text box

1) regex for xxx -> ="^(\d{5}|\d{5}\-\d{4})"   

2) zip code text box with

   a) regex  RegularExpressionValidator   

   b) RequiredFieldValidator               

<asp:TextBox ID="txtZip" runat="server" MaxLength="10"  Width="100px" ></asp:TextBox>

                            <asp:RegularExpressionValidator

                                ID="RequiredFieldValidatorZip"

                              ControlToValidate="txtZip"

                              ValidationExpression="^(\d{5}|\d{5}\-\d{4})$"

                              ErrorMessage="Zip code must be numeric nnnnn or nnnnn-nnnn."

                              Display="dynamic"

                              RunAt="server"></asp:RegularExpressionValidator>

                               <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Zip is a required field!" ControlToValidate="txtZip"></asp:RequiredFieldValidator>

 

Thursday, August 28, 2008

 

Windows XP Backup

http://www.microsoft.com/windowsxp/using/setup/learnmore/bott_03july14.mspx

Wednesday, August 13, 2008

Generic  xmlTextReader
 
Original article:
 
 
                    ////------------------------------------------------------------------
                    ////convert XML string to MemoryStream
                    ////------------------------------------------------------------------
                    MemoryStream memoryStream = new MemoryStream();
                    byte[] data = Encoding.Unicode.GetBytes(strippedXml);
                    memoryStream.Write(data, 0, data.Length);
                    memoryStream.Position = 0;
 
                    ////------------------------------------------------------------------
                    ////convert MemoryStream to xmlTextReader
                    ////------------------------------------------------------------------
                    //XmlTextReader xmlTextReader = new XmlTextReader(Server.MapPath("test.xml"));
                    XmlTextReader xmlTextReader = new XmlTextReader(memoryStream);
 
                    ////------------------------------------------------------------------
                    ////
                    ////------------------------------------------------------------------
                    while (xmlTextReader.Read())
                    {
                        switch (xmlTextReader.NodeType)
                        {
                            case XmlNodeType.Element:
                                Debug.WriteLine(xmlTextReader.Name.ToString());
                                break;
                            case XmlNodeType.Text:
                                Debug.WriteLine(xmlTextReader.Value.ToString());
                                break;
                            case XmlNodeType.EndElement:
                                Debug.WriteLine(xmlTextReader.Name.ToString());
                                break;
                        }
                    }

Monday, August 11, 2008

Original Article:

http://bytes.com/forum/thread176986.html

Is there a simple way to indent xml with dotnet? SQL Server returns a long xml string that is hard
> to read.[/color]

XmlReader r = new XmlTextReader(new StringReader(myXML));
StringWriter sw = new StringWriter();
XmlTextWriter w = new XmlTextWriter(sw);
w.Formatting = Formatting.Indented;
while (r.Read())
w.WriteNode(r, false);
w.Close();
r.Close();
Console.WriteLine(sw.ToString());
--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Thursday, July 31, 2008

 

Users Guide

http://cvsgui.sourceforge.net/winhtml/wincvs11.htm

 

 

Users Guide

http://cvsgui.sourceforge.net/winhtml/wincvs11.htm

Monday, July 28, 2008

1) http://blogs.msdn.com/visio/archive/2006/06/13/624391.aspx

1a) http://office.microsoft.com/en-us/visio/HA011822551033.aspx

2) http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.visio.developer&tid=bc85a37f-451c-46c1-b18b-5201dc10ec9a&cat=en_US_7dd7f818-5a21-4dac-938b-9ac892ab60f3&lang=en&cr=US&sloc=&p=1

Hi,
I am trying to programatically automate the Org Chart Wizard(Visio 2003) in
C#. But when I attempt to connect to a SQL Server 2005, I get an error
message- "Invalid data. Your data file is empty".
I tried programming Excel file to be the data source, it worked fine.
I manually ran the wizard using the SQL data source, it worked fine.
But when I try to code it to work with the same SQL Server data source, I
get this error. It is able to connect to the data source but it is not able
to connect to the database.
I tried changing the name of the datasource, changing it to a different
server, tried connecting it to different databases but it does not work for
any database.

The code for connecting to database is-

commandPart = "/DATASOURCE="
+ formatHelper.StringToFormulaForString(data_source_name);
commandPart = commandPart + "," + "/TABLE=";
commandPart = commandPart +
formatHelper.StringToFormulaForString(Table_containing_information);
commandPart = commandPart + "," + "/DBQUALIFIER=";
commandPart = commandPart +
formatHelper.StringToFormulaForString(database_name);
chartWizard.Run(command + commandPart);


I tried running the orgwiz.exe with command line arguements, but again it
can connect to the data source but it says "Invalid data. Your data file is
empty"
Please help.
Thanks,
Archana

 

 

 

1) nHibernate Quick Start Guide

http://www.hibernate.org/362.html

 1a) NHibernate Best Practices with ASP.NET, 1.2nd Ed

http://www.codeproject.com/KB/architecture/NHibernateBestPractices.aspx

2) http://www.beansoftware.com/asp.net-tutorials/nhibernate-log4net.aspx

Tuesday, April 29, 2008

find columns and tables in a view

 

SELECT  vObj.name AS vName, vObj.id AS vID, vObj.xtype AS vType,

          dep.depid, dep.depnumber, tObj.name AS tName, col.colid,

          col.name AS cName

FROM         sysobjects vObj LEFT OUTER JOIN

             sysdepends dep ON vObj.id = dep.id LEFT OUTER JOIN

             sysobjects tObj ON dep.depid = tObj.id LEFT OUTER JOIN

             syscolumns col ON dep.depnumber = col.colid

                   AND tObj.id = col.id

WHERE   vObj.xtype = 'V' And vObj.category = 0

and   vObj.name = 'vw1_inv_item_det'

ORDER BY vObj.name, tObj.name, col.name

 

Saturday, April 26, 2008

original article:

http://sqlserver2000.databases.aspfaq.com/can-i-make-sql-server-format-dates-and-times-for-me.html

 

Many people have asked if there is a way to make SQL Server behave the way FORMAT works in VB (and FormatDateTime in VBScript). What they'd like to see is the ability to tell SQL Server to format a date with long date and time, or in MM/DD/YYYY format, instead of having to memorize existing format conversion numbers and/or manipulate the strings themselves. For example, to get today's date in YYYYMMDD format, you currently need to call the following: 
 
SELECT CONVERT(CHAR(8), GETDATE(), 112)
 
What does the 112 mean? Nothing. It's just an arbitrary number representing this specific format (Kalen Delaney's Inside SQL Server 2000 has a detailed explanation of the more commonly-used conversions). 
 
Now, wouldn't it be nice to be able to say this: 
 
SELECT CONVERT(VARCHAR, GETDATE(), 'YYYYMMDD')
 

 
Well, now you can, if you're using SQL Server 2000. I designed this scalar user-defined function for specifically this purpose. 
 
CREATE FUNCTION dbo.FormatDateTime 

    @dt DATETIME, 
    @format VARCHAR(16) 

RETURNS VARCHAR(64) 
AS 
BEGIN 
    DECLARE @dtVC VARCHAR(64) 
    SELECT @dtVC = CASE @format 
 
    WHEN 'LONGDATE' THEN 
 
        DATENAME(dw, @dt) 
        + ',' + SPACE(1) + DATENAME(m, @dt) 
        + SPACE(1) + CAST(DAY(@dt) AS VARCHAR(2)) 
        + ',' + SPACE(1) + CAST(YEAR(@dt) AS CHAR(4)) 
 
    WHEN 'LONGDATEANDTIME' THEN 
 
        DATENAME(dw, @dt) 
        + ',' + SPACE(1) + DATENAME(m, @dt) 
        + SPACE(1) + CAST(DAY(@dt) AS VARCHAR(2)) 
        + ',' + SPACE(1) + CAST(YEAR(@dt) AS CHAR(4)) 
        + SPACE(1) + RIGHT(CONVERT(CHAR(20), 
        @dt - CONVERT(DATETIME, CONVERT(CHAR(8), 
        @dt, 112)), 22), 11) 
 
    WHEN 'SHORTDATE' THEN 
 
        LEFT(CONVERT(CHAR(19), @dt, 0), 11) 
 
    WHEN 'SHORTDATEANDTIME' THEN 
 
        REPLACE(REPLACE(CONVERT(CHAR(19), @dt, 0), 
            'AM', ' AM'), 'PM', ' PM') 
 
    WHEN 'UNIXTIMESTAMP' THEN 
 
        CAST(DATEDIFF(SECOND, '19700101', @dt) 
        AS VARCHAR(64)) 
 
    WHEN 'YYYYMMDD' THEN 
 
        CONVERT(CHAR(8), @dt, 112) 
 
    WHEN 'YYYY-MM-DD' THEN 
 
        CONVERT(CHAR(10), @dt, 23) 
 
    WHEN 'YYMMDD' THEN 
 
        CONVERT(VARCHAR(8), @dt, 12) 
 
    WHEN 'YY-MM-DD' THEN 
 
        STUFF(STUFF(CONVERT(VARCHAR(8), @dt, 12), 
        5, 0, '-'), 3, 0, '-') 
 
    WHEN 'MMDDYY' THEN 
 
        REPLACE(CONVERT(CHAR(8), @dt, 10), '-', SPACE(0)) 
 
    WHEN 'MM-DD-YY' THEN 
 
        CONVERT(CHAR(8), @dt, 10) 
 
    WHEN 'MM/DD/YY' THEN 
 
        CONVERT(CHAR(8), @dt, 1) 
 
    WHEN 'MM/DD/YYYY' THEN 
 
        CONVERT(CHAR(10), @dt, 101) 
 
    WHEN 'DDMMYY' THEN 
 
        REPLACE(CONVERT(CHAR(8), @dt, 3), '/', SPACE(0)) 
 
    WHEN 'DD-MM-YY' THEN 
 
        REPLACE(CONVERT(CHAR(8), @dt, 3), '/', '-') 
 
    WHEN 'DD/MM/YY' THEN 
 
        CONVERT(CHAR(8), @dt, 3) 
 
    WHEN 'DD/MM/YYYY' THEN 
 
        CONVERT(CHAR(10), @dt, 103) 
 
    WHEN 'HH:MM:SS 24' THEN 
 
        CONVERT(CHAR(8), @dt, 8) 
 
    WHEN 'HH:MM 24' THEN 
 
        LEFT(CONVERT(VARCHAR(8), @dt, 8), 5) 
 
    WHEN 'HH:MM:SS 12' THEN 
 
        LTRIM(RIGHT(CONVERT(VARCHAR(20), @dt, 22), 11)) 
 
    WHEN 'HH:MM 12' THEN 
 
        LTRIM(SUBSTRING(CONVERT( 
        VARCHAR(20), @dt, 22), 10, 5) 
        + RIGHT(CONVERT(VARCHAR(20), @dt, 22), 3)) 
 
    ELSE 
 
        'Invalid format specified' 
 
    END 
    RETURN @dtVC 
END 
GO
 
(If you're using SQL Server 7.0, you can't create UDFs; so, I suppose you could put this logic into a stored procedure, and put the result into an output parameter.) 
 
Sample usage: 
 
DECLARE @now DATETIME 
SET @now = GETDATE() 
 
PRINT dbo.FormatDateTime(@now, 'LONGDATE') 
PRINT dbo.FormatDateTime(@now, 'LONGDATEANDTIME') 
PRINT dbo.FormatDateTime(@now, 'SHORTDATE') 
PRINT dbo.FormatDateTime(@now, 'SHORTDATEANDTIME') 
PRINT dbo.FormatDateTime(@now, 'UNIXTIMESTAMP') 
PRINT dbo.FormatDateTime(@now, 'YYYYMMDD') 
PRINT dbo.FormatDateTime(@now, 'YYYY-MM-DD') 
PRINT dbo.FormatDateTime(@now, 'YYMMDD') 
PRINT dbo.FormatDateTime(@now, 'YY-MM-DD') 
PRINT dbo.FormatDateTime(@now, 'MMDDYY') 
PRINT dbo.FormatDateTime(@now, 'MM-DD-YY') 
PRINT dbo.FormatDateTime(@now, 'MM/DD/YY') 
PRINT dbo.FormatDateTime(@now, 'MM/DD/YYYY') 
PRINT dbo.FormatDateTime(@now, 'DDMMYY') 
PRINT dbo.FormatDateTime(@now, 'DD-MM-YY') 
PRINT dbo.FormatDateTime(@now, 'DD/MM/YY') 
PRINT dbo.FormatDateTime(@now, 'DD/MM/YYYY') 
PRINT dbo.FormatDateTime(@now, 'HH:MM:SS 24') 
PRINT dbo.FormatDateTime(@now, 'HH:MM 24') 
PRINT dbo.FormatDateTime(@now, 'HH:MM:SS 12') 
PRINT dbo.FormatDateTime(@now, 'HH:MM 12') 
PRINT dbo.FormatDateTime(@now, 'goofy')

Sunday, April 20, 2008

C# Excel Export from ASP.NET Page

 

-----------------

--web Page - ExcelExport.aspx

-----------------

 

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="ExcelExport.aspx.cs" Inherits="Forms_Techniques_ExcelExport" Title="Untitled Page" %>

 

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <asp:GridView ID="GridView1" runat="server">

    </asp:GridView>

    <br />

   <asp:LinkButton ID="LinkButton1" runat="server"

       

        onclientclick="window.open('ExcelExport.aspx?showExcel=true', 'Show_Excel','width=700,height=500,resizable=1,status=1,toolbar=1,menubar=1,scrollbars=1,location=0');"

        Font-Size="Small">Export Data to Excel</asp:LinkButton>

    </asp:Content>

 

-----------------

--Code Behind

-----------------

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

//using System.Xml.Linq;

 

public partial class Forms_Techniques_ExcelExport : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        dsContacts ds = new dsContacts();

        dsContacts.ContactDataTable dt = ds.Contact;

        //dsContactsTableAdapters.ContactTableAdapter ta = new dsContactsTableAdapters.ContactTableAdapter();

        //ta.Fill(dt);

        Guid g = new Guid();

        if (Request.QueryString["showExcel"] == null)

            {

                //------------------------------------------------

                //- First Time load, show Export Link Button

                //------------------------------------------------

                //string excelHTML = "<a style=\"font-size: xx-small; font-family: Verdana\" href=\"Javascript:void(0)\" onclick=\"window.open('ExcelExport.aspx?showExcel=true', 'Show_Excel','width=700,height=500,resizable=1,status=1,toolbar=1,menubar=1,scrollbars=1,location=0');\"><font color=blue><u>Export Data to Excel</u></font></a>&nbsp;&nbsp;";

                //Response.Write(excelHTML);

 

                this.GridView1.DataSource = dt;

                this.GridView1.DataBind();

            }

            else

            {

                //------------------------------------------------

                //User clicked Export Link Button

                //------------------------------------------------

               

 

                RenderExcel objRenderExcel = new RenderExcel();

                //string[] arr = {

                //     "a",

                //         "B",

                //         "C",

                //     "D",

                //     "e"};

 

                //objDatasetToExcel.AddRow("Coupon Bar Chart",

                //    "Coupon;Start Date;End Date;Prints;Etc",

                //    arr);

 

                //objDatasetToExcel.AddTable(dt);

                objRenderExcel.ConvertDataSet(Response, ds);

            }

 

    }

}

 

-----------------

--Class

-----------------

 

using System;

using System.Data;

using System.Configuration;

using System.IO;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

//using System.Xml.Linq;

 

/// <summary>

/// Summary description for RenderExcel

/// </summary>

public class RenderExcel

{

    public RenderExcel()

    {

        //

        // TODO: Add constructor logic here

        //

    }

    public void ConvertDataSet(HttpResponse response, DataSet ds)

    {

        try

        {

            //first let//s clean up the response.object

            response.Clear();

            response.Charset = "";

            //set the response mime type for excel

            response.ContentType = "application/vnd.ms-excel";

            //create a string writer

            //instantiate a datagrid

            DataGrid dg = new DataGrid();

            //set the datagrid datasource to the dataset passed in

 

            for (int i = 0; i < ds.Tables.Count; i++)

            {

                //---------------------------------------------------------------------------

                //table name

                //---------------------------------------------------------------------------

                DataSet littleDs = new DataSet();

                DataTable dataTable = new DataTable(ds.Tables[i].TableName);

                DataColumn column = new DataColumn();

                column.DataType = System.Type.GetType("System.String");

                column.ColumnName = "Table Name";

                //column.ReadOnly = True

                //column.Unique = True

 

                // Add the Column to the DataColumnCollection.

                dataTable.Columns.Add(column);

 

                //DataColumn column2 = new DataColumn();

                //column2.DataType = System.Type.GetType("System.String");

                //column2.ColumnName = "Row Count";

                //column.ReadOnly = True

                //column.Unique = True

 

                //// Add the Column to the DataColumnCollection.

                //dataTable.Columns.Add(column2);

 

                littleDs.Tables.Add(dataTable);

                String[] arr = { ds.Tables[i].TableName + " - " + ds.Tables[i].Rows.Count.ToString() + " rows"};

                //String[] arr = { ds.Tables[i].TableName, ds.Tables[i].Rows.Count.ToString() };

                littleDs.Tables[0].Rows.Add(arr);

                StringWriter stringWrite = new StringWriter();

                //create an htmltextwriter which uses the stringwriter

                HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);

                dg.DataSource = littleDs.Tables[0];

                //bind the datagrid

                dg.DataBind();

                //tell the datagrid to render itself to our htmltextwriter

                dg.RenderControl(htmlWrite);

                response.Write(stringWrite.ToString());

 

                //---------------------------------------------------------------------------

                //actual data

                //---------------------------------------------------------------------------

                stringWrite = new System.IO.StringWriter();

                //create an htmltextwriter which uses the stringwriter

                htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);

                dg.DataSource = ds.Tables[i];

                //bind the datagrid

                dg.DataBind();

                //tell the datagrid to render itself to our htmltextwriter

                dg.RenderControl(htmlWrite);

                //all that//s left is to output the html

                response.Write(stringWrite.ToString());

            }

            response.End();

            response.Write(""); //prevents "thread aborted" message

        }

        catch (Exception ex)

        {

            string x = ex.ToString();

            System.Diagnostics.Debug.WriteLine(ex.Message);

            //Throw ex

        }

        finally

        {

       

        }

 

    }

}

 

 

Thursday, April 17, 2008

[code:xml]
ASP.NET 2.0: Use VB.NET and C# within the App_Code folder
 
Original Article:  http://pietschsoft.com/post/2006/03/ASPNET-20-Use-VBNET-and-C-within-the-App_Code-folder.aspx


 
Thanks to Chris Pietschmann 

 
There is a way to partition the App_Code folder into sub-folders, one for each set of code files written in the same programming language. Awesome, I didn't have to spend a couple hours converting code from VB.NET to C#!

<configuration>
    <system.web>
        <compilation>
            <codeSubDirectories>
                <add directoryName="VB_Code"/>
                <add directoryName="CS_Code"/>
            </codeSubDirectories>
        </compilation>
    </system.web>
</configuration>

Even if you don't use multiple different programming languages for your code files in the App_Code folder, you could use this feature to organize your sets of related code files into sub-folders.

Step 1: Add the following lines to the web.config

Step 2: Create a sub-folder in the App_Code folder for each language you want to support.
For Example:
/App_Code/VB_Code
/App_Code/CS_Code

Step 3: Place your VB.NET code in the VB_Code folder and place C# code in the CS_Code folder.

Wednesday, April 16, 2008

How To: Configure MachineKey in ASP.NET 2.0

http://msdn2.microsoft.com/en-us/library/ms998288.aspx#paght000007_machinekeyexplained

Saturday, April 12, 2008

 1) Add a file as an "embedded resource"

 

2) if the file is in a "subfolder" note the "folder discussion" below

 

3) client call to class

ResourceFileManager objResourceFileManager = new ResourceFileManager();
string x = objResourceFileManager.ReadResourceString("folder.resorceFile.txt");

4) class

using System;
using System.IO;
using System.Reflection;
 
public class ResourceFileManager
{
    public string ReadResourceString(string resourceFileName)
    {
        //value for our return value
        string resourceValue = string.Empty;
        try
        {
 
            //------------------------------------------------------------------
            //debug - this will actually help you locate callers resourceFileName name
            //eg is resx is in an ASP.NET folder "myFolder", -> "myFolder.resourceFileName"
            //------------------------------------------------------------------
            string[] names = this.GetType().Assembly.GetManifestResourceNames();
 
            //------------------------------------------------------------------
            //get current assembly name
            //------------------------------------------------------------------
            Assembly assembly = this.GetType().Assembly;
            string assemblyName = assembly.GetName().Name;
 
            //------------------------------------------------------------------
            //get resource value (text, string)
            //------------------------------------------------------------------
            StreamReader _textStreamReader
                = new StreamReader(assembly.GetManifestResourceStream(assemblyName + "." + resourceFileName));
 
            resourceValue = _textStreamReader.ReadToEnd();
 
 
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            resourceValue = string.Empty;
        }
        return resourceValue;
    }
}
 

 

 

Tuesday, April 08, 2008

Problem: Microsoft Windows Installer 3.1 Error Code: 0x80070005

 

Solution Steps:

 

http://support.microsoft.com/kb/315353

 

To resolve this issue, follow these steps: 1. Log on to your computer as an administrator.

2. Click Start, and then click Run.

3. In the Open box, type cmd, and then click OK.

4. At the command prompt, typemsiexec.exe /unregister, and then press ENTER.

5. Type msiexec /regserver, and then press ENTER. 

6. Verify that the SYSTEM account has full control access permissions to the HKEY_CLASSES_ROOT hive in the Windows registry. In some cases, you may also have to add Administrator accounts. To do so:Important This section, method, or task contains steps that tell you how to modify the registry. However, serious problems might occur if you modify the registry incorrectly. Therefore, make sure that you follow these steps carefully. For added protection, back up the registry before you modify it. Then, you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click the following article number to view the article in the Microsoft Knowledge Base:

322756 (http://support.microsoft.com/kb/322756/) How to back up and restore the registry in Windows

a.  Click Start, click Run, type regedit in the Open box, and then click OK.

b.  Click the following registry hive: