Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: jQuery Application
Hi ,
 
I am doing the conversion from php chat application to asp.net chat application.
In php chat application work fine,
 
so i am converting now, the problem i am facing from php is, they used some array with session variable i dont know the correct equalent in Asp.net. this is the code
 
in php:
 
$_SESSION['openChatBoxes'][$chat['from']] = "from value";
 
in .net i tried:
 
DirectCast((Session("openChatBoxes")), ArrayList)(getIndexOf(DirectCast((Session("openChatBoxes")), ArrayList), "fromname")) = "messagecontent"
 
Its shows the error message for me as follows
 
"Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"
 
Please help me. its very urgent
 
[Modified: added code formatting]
Posted 20-Jan-10 0:59am
Edited 19-Mar-10 13:50pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
 
public partial class chat : System.Web.UI.Page
{
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 chatHeartbeat()
{
/* Add the Code to get the chat from the databse here and assign the result to datatable dtChat */
 
List<Chattlb> messages = Chating.chat.GetNotRecieved(Session["username"].ToString());
string items = "";
 
foreach (Chattlb message in messages)
{
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.message = sanitize(message.message);
 
items = items + "\"s\":\"0\",\"f\":\"{" + message.userfrom.ToString() + "}\",\"m\":\"{" + message.message + "}\"";
 
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.message + "}\"";
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.send;
 

}
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 message = "Sent at " + timeval;
 
if (Now.Minutes > 180)
{
items += "\"s\":\"2\",\"f\":\"{" + chatbox.ToString() + "}\",\"m\":\"{" + message + "}\"";
if (((Hashtable)(Session["chatHistory"]))[chatbox] != null)
{
((Hashtable)(Session["chatHistory"]))[chatbox] = "";
}
((Hashtable)(Session["chatHistory"]))[chatbox] += "\"s\":\"2\",\"f\":\"{" + chatbox.ToString() + "}\",\"m\":\"{" + message + "}\"";
((Hashtable)(Session["tsChatBoxes"]))[chatbox] = "1";
}
}
}
}
Chating.chat.UpdateRecieved(Session["username"].ToString());
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();
}
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", "<br>");
return text;
}
private int getIndexOf(Hashtable SessionArray, string Value)
{
//try
//{
// return SessionArray.IndexOf((object)Value);
//}
//catch
//{
return 0;
//}
}
 
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 sendChat()
{
string from = Session["username"].ToString(); // Assign Session user name value to $from value
string to = Request["to"]; // Assign POST FORM 'To' value to $to value}
string message = Request["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["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*/
 
Chattlb chatObj = new Chattlb();
chatObj.userto = to;
chatObj.userfrom = from;
chatObj.message = message;
chatObj.send = DateTime.Now;
chatObj.recd = 0;
Chating.chat.InsertChat(chatObj);
 
Response.Write("1");
Response.End();
}
private void closeChat()
{
int chatbox = 1; //value of chatbox
try
{
((Hashtable)(Session["openChatBoxes"]))[chatbox] = null;
}
catch
{
}
Response.Write("1");
}
private void startChatSession()
{
string items = "";
if (Session["openChatBoxes"] != null)
{ // Check the Session variable
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\": \"" + Session["username"].ToString() + "\","); // 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();
}
}
  Permalink  
Comments
beyazcennet at 4-Mar-11 18:30pm
   
attempting this project, have run?
BanuGowri at 23-Sep-11 0:22am
   
hi, in this, "Chating.chat.GetNotRecieved", could you please provide the class Chating.chat
divydivy at 5-Oct-11 3:02am
   
i use code of jquery chat from php to asp.net..but it shows error "The type or namespace name 'Chattlb' could not be found"
if you got result..
So could you help me?.Please.....thax
divydivy at 5-Oct-11 2:40am
   
i use this code..but it shows error "The type or namespace name 'Chattlb' could not be found"
could help me?....thax
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

  Permalink  
Comments
divydivy at 5-Oct-11 3:08am
   
i use code of jquery chat from php to asp.net..but it shows error "The type or namespace name 'Chattlb' could not be found"
could you help me?.Please.....thanx
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I'm trying to convert that project to asp.net too.
Did u had any luck doing it?
 
Bye
  Permalink  
Comments
heling0223 at 5-Jul-10 21:18pm
   
Reason for my vote of 4
fdf
divydivy at 5-Oct-11 3:08am
   
i use code of jquery chat from php to asp.net..but it shows error "The type or namespace name 'Chattlb' could not be found"
could you help me?.Please.....thanx
ravuravu at 14-Mar-13 4:07am
   
hey divydivy chattlb is a class file named Chattlb.i don't know the coding inside Chattlb class file u pls create a class file inside it.the Chattlb assembly error will not see.bye.one thing if u get the answer pls share to me because i need a chat application in asp.net like facebook chat
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

in .net I think you should remove 1 from index. see the updated line here
 
DirectCast((Session("openChatBoxes")), ArrayList)(getIndexOf(DirectCast((Session("openChatBoxes")), ArrayList), "fromname") - 1) = "messagecontent"
 
Hope this will work.
  Permalink  
Comments
heling0223 at 5-Jul-10 21:18pm
   
Reason for my vote of 1
sf
divydivy at 5-Oct-11 3:08am
   
i use code of jquery chat from php to asp.net..but it shows error "The type or namespace name 'Chattlb' could not be found"
could you help me?.Please.....thanx
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Laugh | :laugh: Cool | :cool: Dead | X| Suspicious | :suss: OMG | :OMG: Blush | :O Shucks | :-\ Sigh | :sigh: Laugh | :laugh:
  Permalink  
Comments
divydivy at 5-Oct-11 3:08am
   
i use code of jquery chat from php to asp.net..but it shows error "The type or namespace name 'Chattlb' could not be found"
could you help me?.Please.....thanx
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

please help me.can anyone post the .aspx page code of chat??
  Permalink  
Comments
Sandeep Mewara at 9-Jun-12 7:00am
   
This is not an answer. Further expecting a code is not the way it works here. You need to make effort and share what you have done.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 304
1 Maciej Los 285
2 Sergey Alexandrovich Kryukov 230
3 Shweta N Mishra 186
4 Aajmot Sk 153
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,760


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 9 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100