Click here to Skip to main content
15,889,857 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Extract data from another site. Pin
anubhaw.gupta13-Dec-12 0:52
anubhaw.gupta13-Dec-12 0:52 
GeneralRe: Extract data from another site. Pin
AmitGajjar13-Dec-12 0:54
professionalAmitGajjar13-Dec-12 0:54 
GeneralRe: Extract data from another site. Pin
anubhaw.gupta13-Dec-12 1:03
anubhaw.gupta13-Dec-12 1:03 
GeneralRe: Extract data from another site. Pin
AmitGajjar13-Dec-12 1:05
professionalAmitGajjar13-Dec-12 1:05 
GeneralRe: Extract data from another site. Pin
anubhaw.gupta13-Dec-12 6:06
anubhaw.gupta13-Dec-12 6:06 
GeneralRe: Extract data from another site. Pin
AmitGajjar13-Dec-12 6:12
professionalAmitGajjar13-Dec-12 6:12 
GeneralRe: Extract data from another site. Pin
anubhaw.gupta13-Dec-12 6:30
anubhaw.gupta13-Dec-12 6:30 
QuestionChat Application Pin
GopinathGuru11-Dec-12 16:48
GopinathGuru11-Dec-12 16:48 
protected void Page_Load(object sender, EventArgs e)
{

if (Request.QueryString["action"] != null)
{
if (Session["chatHistory"] == null)
{
Session["chatHistory"] = new Hashtable(); ;
}
if (Session["openChatBoxes"] == null)
{
Session["openChatBoxes"] = new Hashtable();
}
if (Session["tsChatBoxes"] == null)
{
Session["tsChatBoxes"] = new Hashtable();
}
switch (Request.QueryString["action"].ToString())
{
case "chatheartbeat":
{
chatHeartbeat();
break;
}
case "sendchat":
{
sendChat();
break;
}
case "closechat":
{
closeChat();
break;
}
case "startchatsession":
{
startChatSession();
break;
}
}
}

Hashtable s = new Hashtable();
}
private void sendChat()
{
string from = Request.Form["from"];
Session["username"] = from; // Assign Session user name value to $from value
string to = Request.Form["to"]; // Assign POST FORM 'To' value to $to value}
string message = Request.Form["message"]; // Assign POST FORM 'message' value to $message value


if (Session["openChatBoxes"] != null)
((Hashtable)(Session["openChatBoxes"]))[to] = DateTime.Now.ToString("Y-m-d H:i:s");

string messagesan = sanitize(message);
if (Session["chatHistory"] != null)
{
if (((Hashtable)(Session["chatHistory"])).Contains(Request.Form["to"]))
{
((Hashtable)(Session["chatHistory"]))[to] = "";
//((Hashtable)(Session["chatHistory"]))[getIndexOf(((Hashtable)(Session["chatHistory"])), Request["to"])] = "";
}
}
if (Session["chatHistory"] != null)
((Hashtable)(Session["chatHistory"]))[to] += "\"s\":\"1\",\"f\":\"{" + to + "}\",\"m\":\"{" + messagesan + "}\"";
if (Session["tsChatBoxes"] != null)
((Hashtable)(Session["tsChatBoxes"]))[to] = null;

/* Add Insert Query here*/
SqlDataProvider sqd4 = new SqlDataProvider();
string ConnectionString4 = sqd4.ConnectionString;
SqlConnection cnn4 = new SqlConnection(ConnectionString4);
cnn4.Open();
string query4 = "insert into dnn_DNAiusMessage_1 (UserFrom,UserTo,MessageContent,SendTime,Received) Values('" + from + "','" + to + "','" + message
+ "','" + DateTime.Now + "','" + 0 + "')";
SqlCommand cmd4 = new SqlCommand(query4, cnn4);
SqlDataReader reader = cmd4.ExecuteReader();
Response.Write("1");
Response.End();
}
private string sanitize(string text)
{
//text = htmlspecialchars(text, ENT_QUOTES); // Convert the html special characters
text = text.Replace("\n\r", "\n");
text = text.Replace("\r\n", "\n");
text = text.Replace("\n", "
");
return text;
}
private void startChatSession()
{
string from = Request.Form["from"];
Session["username"] = from;
string items = "";
if (Session["openChatBoxes"] != null)
{ // Check the Session variable
System.Collections.Hashtable openChatBoxesArray = (Hashtable)(Session["openChatBoxes"]);
for (int i = 0; i < openChatBoxesArray.Count; i++)
{ // Loop the session array
items += chatBoxSession(i); // Append to Items variable
}
}
if (items != string.Empty)
{
items = items.Substring(0, items.Length - 1);
}
HttpContext.Current.Response.Write("{ ");
HttpContext.Current.Response.Write("\"username\": \"" + HttpContext.Current.User.Identity.Name + "\","); // Display the Username Which is set in the session
HttpContext.Current.Response.Write("\"items\": [");
HttpContext.Current.Response.Write(items);
HttpContext.Current.Response.Write("]");
HttpContext.Current.Response.Write("}");
Response.End();
}
private string chatBoxSession(int chatbox)
{

string items = "";

if (((Hashtable)(Session["chatHistory"]))[chatbox] != null)
{ // Check the Session variable
items = ((Hashtable)(Session["chatHistory"]))[chatbox].ToString();
}

return items;
}
private void closeChat()
{
int chatbox = 1; //value of chatbox
try
{
((Hashtable)(Session["openChatBoxes"]))[chatbox] = null;
}
catch
{
}
Response.Write("1");
}
private int getIndexOf(Hashtable SessionArray, string Value)
{
// try
// {
// return SessionArray.in((object)Value);
// }
// catch
// {
return 0;
//}
}

private void chatHeartbeat()
{
//string to = Request.QueryString["UserName"].ToString();
// Session["username1"] = to; // Assign Session user name value to $from value
/* Add the Code to get the chat from the databse here and assign the result to datatable dtChat */
string ConString = ConfigurationManager.AppSettings["SiteSqlServer"];
CHATDataContext ObjDataContext = new CHATDataContext(ConString);
// var messages = ObjDataContext.GetNotRecieved(User.Identity.Name);
var q = from a in ObjDataContext.dnn_DNAiusMessage_1
where a.UserFrom == User.Identity.Name && a.Received == Convert.ToInt32(1)
select a;


// System.Collections.Generic.GenericCollection<dnn_dnaiusmessage_1> messages = ObjDataContext.GetNotRecieved(User.Identity.Name);
// System.Collections.Generic.List<dnn_dnaiusmessage_1> messages = ObjDataContext.GetNotRecieved(User.Identity.Name);
List<dnn_dnaiusmessage_1> messages = q.AsEnumerable().ToList();
string items = "";

foreach (dnn_DNAiusMessage_1 message in q)
{
if (Session["openChatBoxes"] != null && Session["chatHistory"] != null)
{
if (!((Hashtable)(Session["openChatBoxes"])).Contains(message.UserFrom) && ((Hashtable)(Session["chatHistory"])).Contains(message.UserFrom))
{
items = ((Hashtable)(Session["chatHistory"]))[message.UserFrom].ToString();
}
}

message.MessageContent = sanitize(message.MessageContent);
// Response.Write(message.MessageContent);
//items = items + "{\"s\": \"0\",\"f\": \"" + message.UserFrom.ToString() + "\",\"m\": \"" + "ggg" + "\"}, ";
//items = items + "\"s\":\"0\",\"f\":\"{" + message.UserFrom.ToString() + "}\",\"m\":\"{" + "GOOOOP" + "}\"";

items = items + "{\"s\": \"0\",\"f\": \"" + message.UserFrom.ToString() + "\",\"m\": \"" + message.MessageContent + "\"}, ";

if (Session["chatHistory"] != null)
{
if (!((Hashtable)(Session["chatHistory"])).Contains(message.UserFrom))
{
((Hashtable)(Session["chatHistory"]))[message.UserFrom] = "";

}
}
if (Session["chatHistory"] != null)
((Hashtable)(Session["chatHistory"]))[message.UserFrom.ToString()] += "\"s\":\"0\",\"f\":\"{" + message.UserFrom.ToString() + "}\",\"m\":\"{" + message.MessageContent + "}\"";
if (Session["tsChatBoxes"] != null)
((Hashtable)(Session["tsChatBoxes"]))[message.UserFrom.ToString()] = null; // Unset means clear the session value
if (Session["openChatBoxes"] != null)
((Hashtable)(Session["openChatBoxes"]))[message.UserFrom.ToString()] = message.SendTime;


}
if (Session["openChatBoxes"] != null)
{
Hashtable openChatBoxesArray = (Hashtable)(Session["openChatBoxes"]);
for (int i = 0; i < openChatBoxesArray.Count; i++)
{
int chatbox = i;
if (openChatBoxesArray[i] != null)
{
DateTime time = (DateTime)(openChatBoxesArray[i]);
string timeval = "";
TimeSpan Now = (TimeSpan)(DateTime.Now - time);
timeval = time.ToString("g:iA M dS");
string message1 = "Sent at " + timeval;

if (Now.Minutes > 180)
{
// items = items + "{\"s\": \"0\",\"f\": \"" + message.UserFrom.ToString() + "\",\"m\": \"" + message.MessageContent + "\"}, ";
items += "\"s\":\"2\",\"f\":\"{" + chatbox.ToString() + "}\",\"m\":\"{" + message1 + "}\"";
if (((Hashtable)(Session["chatHistory"]))[chatbox] != null)
{
((Hashtable)(Session["chatHistory"]))[chatbox] = "";
}
((Hashtable)(Session["chatHistory"]))[chatbox] += "\"s\":\"2\",\"f\":\"{" + chatbox.ToString() + "}\",\"m\":\"{" + message1 + "}\"";
((Hashtable)(Session["tsChatBoxes"]))[chatbox] = "0";
}
}
}
}
ObjDataContext.UpdateRecieved(User.Identity.Name);
ObjDataContext.SubmitChanges();
if (items != string.Empty)
{
items = items.Substring(0, items.Length - 1);

}
HttpContext.Current.Response.Write("{ ");
Response.Write("\"items\":[" + items + "]");
HttpContext.Current.Response.Write(" }");
Response.End();

}
Chat Application Code is not Working .Please any
one help me. problem is i am not recieving the message
it will be stored into database.but i am not getting the message in browser. please help me

AnswerRe: Chat Application Pin
AmitGajjar12-Dec-12 5:34
professionalAmitGajjar12-Dec-12 5:34 
QuestionASP.NET Pin
Member 468595610-Dec-12 20:02
Member 468595610-Dec-12 20:02 
AnswerRe: ASP.NET Pin
J4amieC11-Dec-12 0:14
J4amieC11-Dec-12 0:14 
AnswerRe: ASP.NET Pin
fjdiewornncalwe11-Dec-12 6:29
professionalfjdiewornncalwe11-Dec-12 6:29 
JokeRe: ASP.NET Pin
jkirkerx11-Dec-12 12:09
professionaljkirkerx11-Dec-12 12:09 
QuestionASP.NET Pin
Member 468595610-Dec-12 19:59
Member 468595610-Dec-12 19:59 
AnswerRe: ASP.NET Pin
Richard MacCutchan10-Dec-12 21:32
mveRichard MacCutchan10-Dec-12 21:32 
AnswerRe: ASP.NET Pin
AmitGajjar11-Dec-12 6:48
professionalAmitGajjar11-Dec-12 6:48 
QuestionResponse.Redirect behavior Pin
AnalogNerd10-Dec-12 9:11
AnalogNerd10-Dec-12 9:11 
AnswerRe: Response.Redirect behavior Pin
David Mujica10-Dec-12 10:01
David Mujica10-Dec-12 10:01 
GeneralRe: Response.Redirect behavior Pin
AnalogNerd10-Dec-12 10:16
AnalogNerd10-Dec-12 10:16 
AnswerRe: Response.Redirect behavior Pin
Shameel10-Dec-12 21:28
professionalShameel10-Dec-12 21:28 
AnswerRe: Response.Redirect behavior Pin
AmitGajjar11-Dec-12 6:54
professionalAmitGajjar11-Dec-12 6:54 
AnswerRe: Response.Redirect behavior Pin
ZurdoDev12-Dec-12 4:36
professionalZurdoDev12-Dec-12 4:36 
GeneralRe: Response.Redirect behavior Pin
AnalogNerd12-Dec-12 4:46
AnalogNerd12-Dec-12 4:46 
QuestionERROR while updating image in database Pin
Ani199110-Dec-12 6:18
Ani199110-Dec-12 6:18 
GeneralRe: ERROR while updating image in database Pin
jkirkerx10-Dec-12 10:37
professionaljkirkerx10-Dec-12 10:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.