Saturday, December 19, 2009

File Upload in Asp.net

private string IMAGEurl()
{
string saveLocation = "";
string imageurl = "/images/thumbnail/UnknownSuper.gif";
try
{
string imageName = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("\\") + 1);
string extention = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("."));

saveLocation = string.Empty;
saveLocation = Server.MapPath("/images/user");

imageName = txtUsername.Text.ToString() + extention;

saveLocation = saveLocation + "/" + imageName;
// jerry 01-07-2009
Bitmap photo = objvalid.ResizeImage(File1.PostedFile.InputStream, 300, 300);// width height
photo.Save(saveLocation);
//
// File1.PostedFile.SaveAs(saveLocation);

saveLocation = string.Empty;
saveLocation = Server.MapPath("/images/thumbnail");
saveLocation = saveLocation + "/" + imageName;
Bitmap photoFile = objvalid.ResizeImage(File1.PostedFile.InputStream, 64, 64);// width height
photoFile.Save(saveLocation);
imageurl = "/images/thumbnail/" + imageName;
}
catch
{ }
return imageurl;
}

Friday, December 18, 2009

DataSet Creation Dynamically

DataSet Ds = new DataSet();
DataTable Dt = new DataTable();
Ds.Tables.Add(Dt);
Dt.Columns.Add("F_Name");
Dt.Columns.Add("S_Name");
DataRow Dr = Dt.NewRow();
Dt.Rows.Add(Dr);
Dr["F_Name"]="satheesh";
Dr["S_Name"]="mnair";

Tuesday, December 15, 2009

DataGrid--Sample Code

//THE HTML TAGS OF A DATAGRID


<div>
<asp:GridView ID="GridView1" CssClass="xGridViewPro" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" Width="300px" OnRowEditing="GridView1_RowEditing" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowUpdating="GridView1_RowUpdating" AllowPaging="True" ShowFooter="True" OnRowCommand="GridView1_RowCommand" OnPageIndexChanging="GridView1_PageIndexChanging" >
<Columns>

<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblname" runat="server" Text='<%# Bind("name") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtnameEdit" runat="server" Text='<%# Bind("name") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtfootName" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Value">

<ItemTemplate>
<asp:Label ID="lblvalue" runat="server" Text='<%# Bind("value") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtValueEdit" runat="server" Text='<%# Bind("value") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtfootValue" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Comment">

<ItemTemplate>
<asp:Label ID="lblcomment" runat="server" Text='<%# Bind("comment") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtcommentEdit" runat="server" Text='<%# Bind("comment") %>'> </asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtfootComment" runat="server"></asp:TextBox>

</FooterTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="id">
<ItemTemplate>
<asp:Label ID="lblid" runat="server" Text='<%# Bind("id") %>' ></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="BtnADD" runat="server" Text="Add" CommandName="addrow" />
</FooterTemplate>
</asp:TemplateField>
<asp:ButtonField CommandName="rowdelete" Text="Delete" />
<asp:CommandField ShowEditButton="True" />

</Columns>

<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
</div>


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

IN CODE BEHIND-->CODE SAMPLE



protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
Label5.Visible = false;
GridView1.EditIndex = e.NewEditIndex;
loadGrid();

}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
int index = GridView1.EditIndex;
int a = e.RowIndex;
GridViewRow row = GridView1.Rows[index];


Label Codelblid = (Label)GridView1.Rows[e.RowIndex].FindControl("lblid");
TextBox CodetxtnameEdit = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtnameEdit");
TextBox CodetxtValueEdit = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtValueEdit");
TextBox CodetxtcommentEdit = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtcommentEdit");

string id = Codelblid.Text;
string name = CodetxtnameEdit.Text;
string value = CodetxtValueEdit.Text;
string comment = CodetxtcommentEdit.Text;

Label5.Visible = true;
if (UpdateTheDetails(id, name, value, comment))
{
try
{
GlobalValues objGlob = GlobalValues.SET();
}
catch
{
}
GridView1.EditIndex = -1;
loadGrid();
Label5.Text = "Global value Updated Successfully";


}
else
{
Label5.Text = "Sorry..Error ocuured..Global values not updated..";
Label5.BackColor = Color.Red;
}
}
catch { }

}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
Label5.Visible = false;
GridView1.EditIndex = -1;
loadGrid();
}

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
Label5.Visible = true;

if (e.CommandName == "addrow")
{

// int index = Convert.ToInt32(e.CommandArgument);

TextBox CodetxtnameEdit = (TextBox)GridView1.FooterRow.FindControl("txtfootName");
TextBox CodetxtValueEdit = (TextBox)GridView1.FooterRow.FindControl("txtfootValue");
TextBox CodetxtcommentEdit = (TextBox)GridView1.FooterRow.FindControl("txtfootComment");
string name = CodetxtnameEdit.Text;
string value = CodetxtValueEdit.Text;
string comment = CodetxtcommentEdit.Text;
string validSTR=Validate(name, value, comment);
if (validSTR == "true")
{
if (INSERTTheDetails(name, value, comment))
{
loadGrid();

}
}
else
{

Label5.BackColor = Color.Red;

}

}
else if (e.CommandName == "rowdelete")
{
int index = Convert.ToInt32(e.CommandArgument);

Label Codelblid = (Label)GridView1.Rows[index].FindControl("lblid");
string id = Codelblid.Text;
if (DELETETheDetails(id))
{
loadGrid();

}

}
}
catch { }
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
Label5.Visible = false;
GridView1.PageIndex = e.NewPageIndex;
loadGrid();
}

SQL Server Constraints Alexander Chigrik

/*1)Tablename-C_ActiorType
fields--ActiorID--->Pk
--Name --->UK
2)Tablename-C_CreditsMatrix
fields--ActorID---->Fk of ActiorID in C_ActiorType
*/

/* settng the primary key constraint...Unique and not allow null*/
ALTER TABLE C_ActiorType
ADD CONSTRAINT pk_ActiorID PRIMARY KEY (ActiorID)
GO

/*setting the Unique key constraint.....unique&can allow only one null*/
ALTER TABLE C_ActiorType ADD CONSTRAINT IX_Name UNIQUE(Name)
GO

/*drop the constraint*/
ALTER TABLE C_ActiorType drop CONSTRAINT IX_ActorID
GO
/*creating the foriegn key for another primary key*/
ALTER TABLE C_CreditsMatrix
ADD CONSTRAINT fk_ActorID
FOREIGN KEY (ActorID)
REFERENCES C_ActiorType (ActiorID) ON DELETE CASCADE
GO

//Please Refer this links

http://blog.sqlauthority.com/2007/02/05/sql-server-primary-key-constraints-and-unique-key-constraints/

http://mssqlserver.wordpress.com/2006/11/22/difference-between-unique-constraint-and-primary-key/

http://www.mssqlcity.com/Articles/General/using_constraints.htm

Monday, December 7, 2009

State Manaement-Good Article

Please Refer this link

http://www.dotnetjohn.com/articles.aspx?articleid=32

Cache-Asp.net simple example with concept

Please Refer this urls:

http://www.codeproject.com/KB/web-cache/cachingaspnet.aspx
http://aspalliance.com/795_Caching_in_ASPNET

Saturday, December 5, 2009

Impersonation in ASP.NET

Please redfer the urls:

http://www.4guysfromrolla.com/articles/031204-1.aspx
http://www.dotnet-guide.com/impersonation.html