Wednesday, December 7, 2011

Find the Drives and Directories in a Computer


using System.IO;
using System.Data;

public partial class Filepaths : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Get the Drives or Disk info'n present in PC into DriveInfo[] Array..
DriveInfo[] AllDrives = DriveInfo.GetDrives();
foreach(DriveInfo drinfo in AllDrives)
{
Response.Write("Drive Name is "+drinfo.Name+"<br/>"+
"Drive type is "+drinfo.DriveType+"<br/>");
if (drinfo.IsReady == true)
{
Response.Write("VolumeLabel is "+drinfo.VolumeLabel+"<br />"+
"File System is "+drinfo.DriveFormat+"<br/>"+
"Avail Space is "+drinfo.AvailableFreeSpace+"<br />"+
"Avail Space is " + drinfo.TotalFreeSpace + "<br />" +
"Avail Space is " + drinfo.TotalSize + "<br />" +
"");
}
}


//Get the Directories info Present in a Drive "C:\"
DirectoryInfo di = new DirectoryInfo(@"C:\");
// Get only subdirectories that contain the letter "p."
DirectoryInfo[] dirs = di.GetDirectories("*w*");// + "*p*" + "*d*" + "*w*");
Response.Write(dirs.Length);
foreach (DirectoryInfo dinext in dirs)
{
Response.Write("the number of files in "+dinext+" is "+dinext.GetFiles().Length+"+<br/>");
}
}
}
==============================================
OutPut:

Drive Name is C:\
Drive file type Fixed
VolumeLabel is
File System is NTFS
Avail Space is 53018939392
Avail Space is 53018939392
Avail Space is 73402363904
Drive Name is D:\
Drive file type Fixed
VolumeLabel is
File System is NTFS
Avail Space is 167805022208
Avail Space is 167805022208
Avail Space is 176646078464
1the number of files in WINDOWS is 155+


Reference:

Wednesday, November 16, 2011

Create a table at runtime


//CREATING A TABLE
public void createtabel()
{
//create table body i.e, <table>
Table table = new Table();
//Add table properties
table.BackColor = System.Drawing.Color.Gray;
table.Width = Unit.Percentage(100);
table.Height = Unit.Percentage(100);


//Create table row i.e,<tr>
TableRow tablerow = new TableRow();
tablerow.VerticalAlign = VerticalAlign.Top;


//create table cell i.e,<td>1
TableCell tablecell1 = new TableCell();
//tablecell1.Controls.Add();
//add <td> to <tr>
tablerow.Cells.Add(tablecell1);
//create table cell i.e,<td>2
TableCell tablecell2 = new TableCell();
//add <td> to <tr>
tablerow.Cells.Add(tablecell2);
//create table cell i.e,<td>3
TableCell tablecell3 = new TableCell();

//add <td> to <tr>
tablerow.Cells.Add(tablecell3);


//**Add the Table <tr> to Tabale <table>
table.Rows.Add(tablerow);
//*****Add the table control to the page
Page.Controls.Add(table);

}

==================================
Based on gien value of ROWS and COLUMNS




private void CreateDynamicTable()
{

PlaceHolder1.Controls.Clear();
// Fetch the number of Rows and Columns for the table

// using the properties

int tblRows = 3;

int tblCols = 5;

// Create a Table and set its properties

Table tbl = new Table();
tbl.Attributes.Add("style", "Height:100px; width:100px; border:2px solid red; background:gray;");

// Add the table to the placeholder control

PlaceHolder1.Controls.Add(tbl);
//Page.Controls.Add(tbl);

// Now iterate through the table and add your controls

for (int i = 0; i < tblRows; i++)
{

TableRow tr = new TableRow();

for (int j = 0; j < tblCols; j++)
{

TableCell tc = new TableCell();

TextBox txtBox = new TextBox();

txtBox.Text = "RowNo:" + i + " " + "ColumnNo:" + " " + j;

// Add the control to the TableCell

tc.Controls.Add(txtBox);

// Add the TableCell to the TableRow

tr.Cells.Add(tc);

}

// Add the TableRow to the Table

tbl.Rows.Add(tr);

}
PlaceHolder1.Controls.Add(tbl);


// This parameter helps determine in the LoadViewState event,

// whether to recreate the dynamic controls or not



ViewState["dynamictable"] = true;

}





===========================================
Add CSS Propeties Dynamically

-----------

WebPartZone webPartZone = new WebPartZone();
webPartZone.ID = aZoneTitle.Replace(" ", "");
webPartZone.HeaderText = "";// aZoneTitle;
webPartZone.Attributes.Add("style", "height:1000px; width:30%; border:0px solid red; float:left;");
webPartZone.EmptyZoneText = "";



=====================
Note:
Posiible Error: 
Control 'TextBox1' of type 'TextBox' must be placed inside a form tag with runat=server.


Solution:
To Add any Server controls like TextBox or Button in table cell we have use one PlaceHolder control from toolbox and in code behind  add the table control to placeholder as shown below:

PlaceHolder1.Controls.Add(tbl);

Tuesday, October 25, 2011

SQL Queries

REset the Identiy Column to Zero

==================================================
DBCC CHECKIDENT ( tbl_MOduleImages,RESEED,0)

Synatx :
DBCC CHECKIDENT (tbl_name,RESEED,0)


 ------------------------
Copy a table from another Database to current database:

SELECT * INTO Login_AtemptsCheck  FROM DashBoard.dbo.Login_AtemptsCheck
1) Login_AtemptsCheck: Is a New table name in current database
2) DashBoard: Existing database from where we take the table

3)dbo.Login_AtemptsCheck: Tbale name from the database DashBoard which contains data


 Example 2:
select * into new_Table_Name from DataBase_Name.Exixting_Table_Name
=======================================================================
Sql Error handling
http://www.mssqltips.com/sqlservertip/1027/sql-server-2005-try-and-catch-exception-handling/

=====================================================================
Geometry  Data Type in sql Example
http://www.freddes.se/2008/09/25/net-and-spatial-data-with-sql-server-2008-part-1/
2) http://robertoschiabel.wordpress.com/2011/03/16/locations-in-this-area-sql-server-geography-datatype/

Friday, October 21, 2011

Dynamic Table Creation



Table tb = new Table();
    tb.ID = "myTable";
    tb.Height = Unit.Pixel(200);
    tb.Width = Unit.Pixel(200);
    tb.BorderWidth = Unit.Pixel(3);
    tb.CellPadding = 2;
    tb.CellSpacing = 2;
    for (int i = 0; i < 3; i++)
    {
        TableRow tr = new TableRow();
        tr.ID = "row" + i.ToString();
        for (int j = 0; j < 2; j++)
        {
            TableCell tc = new TableCell();
            tc.ID = "cell" + i.ToString() + j.ToString();
            tc.Text = "cell" + i.ToString() + j.ToString();
            tr.Cells.Add(tc);
        }
        tb.Rows.Add(tr);
    }
    form1.Controls.Add(tb);


reference:
http://www.codeproject.com/KB/aspnet/DynamicServerControls.aspx

Wednesday, October 12, 2011

DataList in ASp.net

http://forums.asp.net/t/1162928.aspx/1


Re: how to find control from header template of a datalist?

Jan 04, 2010 07:28 AM | LINK
Instead of  finding  the control in the header template of datalist in page load event .you can put the code which you want to execute after finding the control inside a function and then call that function from the header template.Below is a example:->
<asp:DataList ID="dtlisFirstSubCategories" runat="server">
        <HeaderTemplate>
            <%#GetParentCategoryName() %>
        </HeaderTemplate>
        <ItemTemplate>
            <asp:LinkButton ID="lbtnSubCategory" runat="server" CommandArgument='<%#Eval("ProductCategoryID")%>'
                Text='<%#Eval("Name")%>'  PostBackUrl='<%#"~/Category.aspx?parentCategoryID="+Eval("ProductCategoryID") %>'
                OnClick="lbtnSubCategory_Click"> </asp:LinkButton>
        </ItemTemplate>
    </asp:DataList>


now in cs file you can put code as follows:->
public string GetParentCategoryName()
    {
String parentCategoryName="";    
  //add logic here to get the category name

return parentCategoryName;
    }

Friday, September 30, 2011

Webpart Themes

.css file Contains

{
width:1100px;
height:1002px;
}
.Zone
{
Width:250px;
border:3 solid black;
float:left;
}
.PartTitleStyle {
background-color:#C1D4E3;
height:25px;
font-size:8px;
padding:0px 0px 5px 10px;
background-image:url(../images/boxHeaderTopLeft.gif);
background-repeat: no-repeat; background-position: left top; }
.PartTitleStyle table {
background-image:url(../images/boxHeaderTopRight.gif);
background-repeat: no-repeat;
background-position: right top;}

.PartTitleStyle table tr td {
padding:10px 10px 0 10px;}
.PartTitleStyle table tr td span {
font-size:12px;
font-weight:bold;
background-color:#C1D4E3;
padding-right: -10px; }

.PartStyle {
background-color: #F8F8f0;
border: solid 1px #DDDDDD; }
.PartZone {
border:dashed 1px #DDDDDD; }
.PartZoneHeader {
height:0px;
display:none; }
==============================
Create a .Skin file
and Write the Code

<MSDLL:WebPartZone HeaderText=" " EmptyZoneText=" " runat="server"
HeaderStyle-CssClass="PartZoneHeader"
CssClass="Zone"
BorderStyle="None"
PartStyle-CssClass="PartStyle"
PartTitleStyle-CssClass="PartTitleStyle"
PartChromeStyle-BorderColor="White"
MenuPopupStyle-BackColor="#C1D4E3"
MenuPopupStyle-Font-Size="10px">
</MSDLL:WebPartZone>
===============================
in your .aspx
page Just add your control and Drag the .css into your .aspx design page
========================
<MSDLL:WebPartZone ID="MiddleZone" runat="server" class="Zone">

<ZoneTemplate>
</ZoneTemplate>
</MSDLL:WebPartZone>

Here I used MSDLL=MicroSoft dll file.... for browser compalibilty issue for Drag and Drop..
1) we use Microsoft.Web.Preview.dll file 
2) in Web.config file

<!--Adding Asembly-->
<system.web>


<pages controlRenderingCompatibilityVersion="4.0" theme="Controls" clientIDMode="AutoID">
<controls>
<add tagPrefix="MSDLL" namespace="Microsoft.Web.Preview.UI.Controls.WebParts" assembly="Microsoft.Web.Preview" />
<add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting" assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add tagPrefix="Ajax" namespace="AjaxControlToolkit" assembly="AjaxControlToolkit"/>
</controls>
</pages>
</system.web>


in the above html code tagPrefix="MSDLL" ,menas the webpartZone,Webpartmanger we are using is a Microsoft Webpartmanger,webpartZone....


in .aspx.cs file Use the name space as

using Microsoft.Web.Preview.UI.Controls.WebParts;

Reference from
-------------
http://live.mscommunity.net/blogs/borissevo/archive/2007/10/04/rounded-corners-for-web-parts-in-asp-net-2-0.aspx