Nitin Sharma

Nitin Sharma

  • NA
  • 154
  • 61.7k

chat and status update coding like FB

Apr 16 2014 3:30 AM
Dear Friends i am try to code a site which can provide the chating option, and also status update
i have code for status update one multi line textbox, one file upload and one button , if we enter ant text and post it will display but if i post ant image than this code will not work , i have past all my code here please help me .
This is the Design page code:
 
<pre lang="xml">&lt;%@ Control Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeFile=&quot;LatestUpdates.ascx.cs&quot; Inherits=&quot;Controls_Latest&quot; %&gt;
&lt;style type=&quot;text/css&quot;&gt;
.styleLatestUpdates
{
width: 400px;
}
.stylePost
{
width: 98%;
height: 90px;
}
.styleComment
{
width: 103px;
}
.stylePostPic
{
width: 110px;
vertical-align: top;
}
&lt;/style&gt;
&lt;table style=&quot;width: 550px&quot; align=&quot;center&quot;&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot; style=&quot;padding-left: 10px&quot;&gt;
&lt;asp:Label ID=&quot;lblName&quot; runat=&quot;server&quot; Font-Bold=&quot;True&quot; Font-Names=&quot;Georgia&quot; Font-Size=&quot;Large&quot;&gt;&lt;/asp:Label&gt;
&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;
&lt;asp:LinkButton ID=&quot;btnAddAsFriend&quot; runat=&quot;server&quot; Text=&quot;Add As Friend&quot; Font-Bold=&quot;True&quot;
Font-Italic=&quot;True&quot; OnClick=&quot;btnAddAsFriend_Click&quot;&gt;&lt;/asp:LinkButton&gt;
&lt;br /&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;asp:UpdatePanel ID=&quot;UpdatePanel1&quot; runat=&quot;server&quot;&gt;
&lt;ContentTemplate&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;styleLatestUpdates&quot;&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;table style=&quot;width: 550px&quot;&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;
&lt;panel runat=&quot;server&quot; id=&quot;pnlStatus&quot;&gt;
&lt;asp:TextBox ID=&quot;txtWhatsOnYourHeart&quot; runat=&quot;server&quot; Height=&quot;59px&quot; TextMode=&quot;MultiLine&quot; Width=&quot;543px&quot;&gt;&lt;/asp:TextBox&gt;
&lt;br /&gt;
&lt;asp:Button ID=&quot;btnPost&quot; runat=&quot;server&quot; BackColor=&quot;#CCCCCC&quot; BorderColor=&quot;#CCCCCC&quot; BorderStyle=&quot;Ridge&quot; BorderWidth=&quot;1px&quot; Font-Bold=&quot;True&quot; ForeColor=&quot;#333333&quot; OnClick=&quot;btnPost_Click&quot;
Text=&quot;Post&quot; Width=&quot;52px&quot; /&gt;
&lt;asp:FileUpload ID=&quot;FileUpload1&quot; runat=&quot;server&quot; /&gt; &lt;asp:UpdateProgress ID=&quot;ProgressBar&quot; runat=&quot;server&quot;&gt;
&lt;ProgressTemplate&gt;
&lt;asp:Image ID=&quot;Image1&quot; runat=&quot;server&quot; ImageUrl=&quot;~/images/loading.gif&quot; /&gt;
&lt;/ProgressTemplate&gt;
&lt;/asp:UpdateProgress&gt;
&lt;/panel&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;hr /&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;asp:DataList ID=&quot;dlPosts&quot; runat=&quot;server&quot; Width=&quot;550px&quot;&gt;
&lt;ItemTemplate&gt;
&lt;div&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;stylePost&quot;&gt;
&lt;tr&gt;
&lt;td class=&quot;stylePostPic&quot; rowspan=&quot;2&quot; align=&quot;center&quot;&gt;
&lt;asp:ImageButton ID=&quot;YourPic&quot; runat=&quot;server&quot; BorderColor=&quot;Black&quot; BorderStyle=&quot;Ridge&quot;
BorderWidth=&quot;1px&quot; Height=&quot;60px&quot; ImageUrl='&lt;%# &quot;ImageHandler.ashx?RegisterId=&quot;+ Eval(&quot;RegisterId&quot;) %&gt;'
Width=&quot;60px&quot; OnClick=&quot;YourPic_Click&quot; CommandArgument='&lt;%#Bind(&quot;RegisterId&quot;) %&gt;' /&gt;
&lt;/td&gt;
&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;
&lt;asp:Label runat=&quot;server&quot; ID=&quot;lblName&quot; ForeColor=&quot;Blue&quot; Font-Bold=&quot;True&quot; Font-Italic=&quot;True&quot;&gt;
&lt;%# DataBinder.Eval(Container.DataItem, &quot;Name&quot;)%&gt; &amp;nbsp;Posted:&lt;/asp:Label&gt;
&lt;div style=&quot;width: 300px&quot;&gt;
&lt;%# DataBinder.Eval(Container.DataItem, &quot;Post&quot;)%&gt;
&lt;/div&gt;
&lt;div style=&quot;width:300px&quot;&gt;
&lt;%#DataBinder.Eval(Container.DataItem,&quot;img&quot;) %&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;right&quot; valign=&quot;bottom&quot;&gt;
&lt;asp:Label runat=&quot;server&quot; ID=&quot;lblPostedOn&quot; ForeColor=&quot;Black&quot; Font-Italic=&quot;True&quot; Font-Size=&quot;Small&quot;&gt;
Posted On: &lt;%# DataBinder.Eval(Container.DataItem, &quot;PostDate&quot;)%&gt;
&lt;/asp:Label&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;br /&gt;
&lt;hr /&gt;
&lt;/div&gt;
&lt;/ItemTemplate&gt;
&lt;/asp:DataList&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/ContentTemplate&gt;
&lt;Triggers&gt;
&lt;asp:AsyncPostBackTrigger ControlID=&quot;btnPost&quot; EventName=&quot;Click&quot; /&gt;
&lt;/Triggers&gt;
&lt;/asp:UpdatePanel&gt;</pre>
This is the logical post button code :
 
String ss, ss1;
protected void btnPost_Click(object sender, EventArgs e)
{
//if (FileUpload1.HasFile)
//{
// ss = Server.MapPath("img");
//ss = ss+"/" +FileUpload1.FileName;
ss1 = "~\\img\\" + FileUpload1.FileName.ToString();
FileUpload1.PostedFile.SaveAs(Server.MapPath(ss1));
string PostDate = DateTime.Now.ToLongDateString();
string InsertPostquery = "Insert into Posts (Post,FromId,ToId,PostDate,img) values('" + txtWhatsOnYourHeart.Text + "','" + Convert.ToInt32(Session["UserId"]) + "','" + Convert.ToInt32(Session["CurrentProfileId"]) + "','" + PostDate + "','" + ss1 + "')";
Database.InsertData(InsertPostquery);
LatestUpdates();
txtWhatsOnYourHeart.Text = string.Empty;
//}
//else
//{
// string PostDate = DateTime.Now.ToLongDateString();
// string InsertPostquery = "Insert into Posts (Post,FromId,ToId,PostDate,img)values('" + txtWhatsOnYourHeart.Text + "','" + Convert.ToInt32(Session["UserId"]) + "','" + Convert.ToInt32(Session["CurrentProfileId"]) + "','" + PostDate + "','" + ss1 + "')";
// Database.InsertData(InsertPostquery);
// LatestUpdates();
// txtWhatsOnYourHeart.Text = string.Empty;
// }
}