Click here to Skip to main content
15,915,172 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: How to check session is created or not? Pin
N a v a n e e t h4-Jul-08 1:06
N a v a n e e t h4-Jul-08 1:06 
QuestionAn error has occurred while establishing a connection to the server. Pin
Raghvendra Kumar Roy3-Jul-08 20:15
Raghvendra Kumar Roy3-Jul-08 20:15 
AnswerRe: An error has occurred while establishing a connection to the server. Pin
N a v a n e e t h4-Jul-08 1:08
N a v a n e e t h4-Jul-08 1:08 
QuestionError:Cannot convert type string to int Pin
rockram3-Jul-08 20:05
rockram3-Jul-08 20:05 
AnswerRe: Error:Cannot convert type string to int Pin
Sherin Iranimose3-Jul-08 20:48
Sherin Iranimose3-Jul-08 20:48 
GeneralRe: Error:Cannot convert type string to int Pin
Sutheesh chandran3-Jul-08 21:00
Sutheesh chandran3-Jul-08 21:00 
GeneralRe: Error:Cannot convert type string to int Pin
Sherin Iranimose3-Jul-08 21:21
Sherin Iranimose3-Jul-08 21:21 
GeneralRe: Error:Cannot convert type string to int Pin
rockram4-Jul-08 0:54
rockram4-Jul-08 0:54 
Hello sir
Thanks for your reply
Here is my code:


using System;
using System.IO;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

partial class SpellSuggest : System.Web.UI.Page
{
private string[] strDictArray;
private bool boolDictionaryLoaded = false;
private int intErrors = 0;

protected void Page_Load(object sender, System.EventArgs e)
{

int iCurrentCount = 0;
string[] arrWords;
string strCompleteOriginal = "";
int iWordCount = 0;
//string hfOriginalString.Value, hfCurrentCount.Value, hfErrors.Value, hfWordCount.Value;

char[] chSplit ={ ' ' };
//string strAlternative = "";
int i = 0;
string strText;
strText = Request.QueryString["txtContent"];
strText = strText.Trim();
// If nothing to check, exit the procedure
if (strText == "")
{
return; // TODO: might not be correct. Was : Exit Sub
}
else
{
// Get the string to check
strCompleteOriginal = strText;
}

// First time the page is loaded
if (!IsPostBack)
{
// Initialize current word index to zero
iCurrentCount = 0;
// Initialize total word count to zero
iWordCount = 0;
// Initialize total invalid word count to zero
intErrors = 0;

// Set value of hidden field containing complete original string to check
hfOriginalString.Value = strCompleteOriginal;
// Set value of hidden field containing current index
hfCurrentCount.Value = "0";

// Split into an array of individual words
arrWords = strCompleteOriginal.Split(chSplit);
// Count total number of words
iWordCount = arrWords.Length;
// Set value of hidden field containing total number of words
hfWordCount.Value = Convert.ToString(iWordCount);
// Set value of hidden field containing total number of invalid words
hfErrors.Value = "0";
}
else
{
// Not the first time, split hidden field into an array of individual words
arrWords = hfOriginalString.Value.Split(chSplit);
// Get index for current word in the array
iCurrentCount = Convert.ToInt32(hfCurrentCount.Value);
// Get current number of invalid words from hidden field
intErrors = int.Parse(hfErrors.Value);
}

// Set the current word being checked textbox value
txtCurrent.Text = arrWords[iCurrentCount];

// User has chosen to stop searching
if (Request.Form["cmdCancel"] == "Stop")
{
// Get our array of words from hidden field
arrWords = hfOriginalString.Value.Split(chSplit);
// Get total number of words from hidden field
iWordCount = Convert.ToInt32(hfWordCount.Value);
// Start with the words already corrected
string strReplace = hfFinal.Value;
int j = 0;
// Now add the rest of the un-checked words
for (j = iCurrentCount; j <= iWordCount - 1; j++)
{
strReplace += arrWords[j] + " ";
}

// The last invalid word was never fixed
intErrors -= 1;

// Notify the user and close the spell check window
stopChecking("frmSpellCheck", "txtContent", strReplace);

// Exit the procedure, we're done
return; // TODO: might not be correct. Was : Exit Sub
}

// If we're returning from a suggestion that has been selected or a manually
// entered word
if (Request.Form["cmdNext"] == "Next")
{
// Get our array of words from hidden field
arrWords = hfOriginalString.Value.Split(chSplit);
// Get total number of words from hidden field
iWordCount = Convert.ToInt32(hfWordCount.Value);

// If the user has selected a suggestions form the list
if (txtManual.Text == "")
{
// Update word in array
arrWords[iCurrentCount] = lbSuggestions.SelectedValue;
// Append corrected word to string containing completed valid text
hfFinal.Value += lbSuggestions.SelectedValue + " ";
}
else
{
// If the user has manually entered the word
// Update word in array
arrWords[iCurrentCount] = txtManual.Text;
// Append corrected word to string containing completed valid text
hfFinal.Value += txtManual.Text + " ";
}

// Clear out the Current word and manual word textboxes, ready for the next one
txtManual.Text = "";
txtManual.Text = "";
// Increment the current word index
iCurrentCount += 1;
// Set the hidden field containing the current index
hfCurrentCount.Value = Convert.ToString(iCurrentCount);

// Now carry on checking the rest of the text
for (i = iCurrentCount; i <= iWordCount - 1; i++)
{
// Set the value of the current word being checked textbox
txtCurrent.Text = arrWords[iCurrentCount];

LoadDictArray("dict-large.txt", arrWords[iCurrentCount].Substring(0));
// If the current word contains non-text characters, just add to the final string and move on
if (PrepForSpellCheck(arrWords[iCurrentCount]) == false)
{
hfFinal.Value += arrWords[iCurrentCount] + " ";
// Increment the current word index
iCurrentCount += 1;
// Set the hidden field containing the current index
hfCurrentCount.Value = Convert.ToString(iCurrentCount);
}
// If the current word is a number, just add to the final string and move on
else if (IsNumeric(arrWords[iCurrentCount]))
{
hfFinal.Value += arrWords[iCurrentCount] + " ";
// Increment the current word index
iCurrentCount += 1;
// Set the hidden field containing the current index
hfCurrentCount.Value = Convert.ToString(iCurrentCount);
}
// If the word is valid, just add to the final string and move on
else if (SpellCheck(arrWords[iCurrentCount]))
{
hfFinal.Value += arrWords[iCurrentCount] + " ";
// Increment the current word index
iCurrentCount += 1;
// Set the hidden field containing the current index
hfCurrentCount.Value = Convert.ToString(iCurrentCount);
}
else
{
// Increment the number of invalid words
intErrors += 1;
// Set the hidden field containing the number of invalid words
hfErrors.Value =Convert.ToString(intErrors);
// Invalid word, suggest some alternatives
// Clear out list from previous suggestions
lbSuggestions.Items.Clear();

// Add each suggested word to the list
foreach(string strAlternative in Suggest(arrWords[iCurrentCount]))
{
lbSuggestions.Items.Add(new ListItem(strAlternative, strAlternative));
}

// add the original item to the list of suggestions in case it's not in our dictionary
lbSuggestions.Items.Insert(0, new ListItem(arrWords[iCurrentCount], arrWords[iCurrentCount]));

// select the original item in the list by default
lbSuggestions.SelectedIndex = 0;
break; // TODO: might not be correct. Was : Exit For
}
}

// If we've checked all the words in the original text
if (iCurrentCount == iWordCount)
{
// Notify the user and close the spell check window
finishedChecking("frmSpellCheck", "txtContent", hfFinal.Value);
}

// Exit the procedure, we're done
return; // TODO: might not be correct. Was: Exit Sub
}

// check the current word and if invalid, suggest alternatives
for (i = 0; i <= iWordCount - 1; i++)
{
txtCurrent.Text = arrWords[iCurrentCount];

LoadDictArray("dict-large.txt", String.Left(arrWords[iCurrentCount], 1));
// If the current word contains non-text characters, just add to the final string and move on
if (PrepForSpellCheck(arrWords[iCurrentCount]) == false)
{
hfFinal.Value += arrWords[iCurrentCount] + " ";
// Increment the current word index
iCurrentCount += 1;
// Set the hidden field containing the current index
hfCurrentCount.Value = Convert.ToString(iCurrentCount);
}
// If the current word is a number, just add to the final string and move on
else if (Information.IsNumeric(arrWords[iCurrentCount]))
{
hfFinal.Value += arrWords[iCurrentCount] + " ";
// Increment the current word index
iCurrentCount += 1;
// Set the hidden field containing the current index
hfCurrentCount.Value =Convert.ToString(iCurrentCount);
}
// If the word is valid, just add to the final string and move on
else if (SpellCheck(arrWords[iCurrentCount]))
{
hfFinal.Value += arrWords[iCurrentCount] + " ";
// Increment the current word index
iCurrentCount += 1;
// Set the hidden field containing the current index
hfCurrentCount.Value =Convert.ToString(iCurrentCount);
}
else
{
// Increment the number of invalid words
intErrors += 1;
// Set the hidden field containing the number of invalid words
hfErrors.Value =Convert.ToString(intErrors);
// Invalid word, suggest some alternatives
// Clear out list from previous suggestions
lbSuggestions.Items.Clear();

// Add each suggested word to the list
foreach (string strAlternative in Suggest(arrWords[iCurrentCount]))
{
lbSuggestions.Items.Add(new ListItem(strAlternative, strAlternative));
}

// add the original item to the list of suggestions in case it's not in our dictionary
lbSuggestions.Items.Insert(0, new ListItem(arrWords[iCurrentCount], arrWords[iCurrentCount]));

// select the original item in the list by default
lbSuggestions.SelectedIndex = 0;

// Exit the loop so that the user can select a suggestion or
// type their corrected word
break; // TODO: might not be correct. Was : Exit For
}
}

// If we've checked all the words in the original text
if (iCurrentCount == iWordCount)
{
// Notify the user and close the spell check window
finishedChecking("frmSpellCheck", "txtContent", hfFinal.Value);
}

}

private void stopChecking(string strFormName, string strTextboxName, string strText)
{
// Hide the table with the current word and suggestions
tblMain.Visible = false;

// Insert the onload javascript to alert the user that the check has completed
// and update the source textbox and close the spellchecker window
StringBuilder sbJavascript = new StringBuilder();
sbJavascript.Append("<script language=\"javascript\" type=\"text/javascript\">");
sbJavascript.Append("alert(\"The spell check was stopped successfully (" + intErrors + " error(s) were fixed).\");");
sbJavascript.Append("window.opener." + strFormName + "." + strTextboxName + " = '" + strText + "';");
sbJavascript.Append("window.opener." + strFormName + ".cmdCheckSpelling.disabled = false;");
sbJavascript.Append("self.close();");
sbJavascript.Append("</script>");

Page.ClientScript.RegisterStartupScript(System.Type.GetType("System.String"), "onload", sbJavascript.ToString);
}

private void finishedChecking(string strFormName, string strTextboxName, string strText)
{
// Hide the table with the current word and suggestions
tblMain.Visible = false;

// Insert the onload javascript to alert the user that the check has completed
// and update the source textbox and close the spellchecker window
StringBuilder sbJavascript = new StringBuilder();
sbJavascript.Append("<script language=\"javascript\" type=\"text/javascript\">");
sbJavascript.Append("alert(\"The spell check has completed successfully (" + intErrors + " error(s) found).\");");
sbJavascript.Append("window.opener." + strFormName + "." + strTextboxName + " = '" + strText + "';");
sbJavascript.Append("window.opener." + strFormName + ".cmdCheckSpelling.disabled = false;");
sbJavascript.Append("self.close();");
sbJavascript.Append("</script>");

Page.ClientScript.RegisterStartupScript(System.Type.GetType("System.String"), "onload", sbJavascript.ToString);
}

private void LoadDictArray(string strPath, string strBegin)
{
bool boolStart = false;
string strCurrent = "";
string strFinal = "";

// Open our dictionary file
StreamReader srDictionary = new StreamReader(HttpContext.Current.Server.MapPath(strPath));

// Check each line and loop while there is another
while (srDictionary.Peek() != -1)
{
// Read the current line
strCurrent = srDictionary.ReadLine();
// Does the first character match our word's
if (String.LCase(String.Left(strCurrent, 1)) == String.LCase(strBegin))
{
boolStart = true;
// Only add words beginning with the same letter as the current word
strFinal += strCurrent + Constants.vbNewLine;
}

// Exit, we have all our relevant words
if(boolStart == true & String.LCase(String.Left(strCurrent, 1)) != String.LCase(strBegin))
{
break; // TODO: might not be correct. Was : Exit While
}
}

// Close the streamreader
srDictionary.Close();

// Split our string into an array of suitable words
strDictArray = String.Split(strFinal, Constants.vbNewLine);
strCurrent.Substring(1).ToLower() == strBegin.ToLower());
}

private bool PrepForSpellCheck(string strWord)
{
string strValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'-";
int i = 0;
string strLetter = "";
bool boolValid = false;

for (i = 1; i <= String.Len(strWord); i++)
{
strLetter = String.Mid(strWord, i, 1);

if (String.InStr(strValidChars, strLetter) > 0)
{
boolValid = true;
}
else if (i < String.Len(strWord))
{
boolValid = false;
break; // TODO: might not be correct. Was : Exit For
}
}

return boolValid;
}

private bool SpellCheck(string strWord)
{
int iFirst;
int iLast;
int iMiddle;
bool retValue = false;

if (String.Len(strWord) > 1)
{
iFirst = Information.LBound(strDictArray);
iLast = Information.UBound(strDictArray);

while (iFirst <= iLast)
{
iMiddle = (iFirst + iLast) / 2;

if (String.LCase(strDictArray(iMiddle)) == String.LCase(strWord))
{
retValue = true;
break; // TODO: might not be correct. Was : Exit Do
}
else if (String.LCase(strDictArray(iMiddle)) < String.LCase(strWord))
{
iFirst = iMiddle + 1;
}
else
{
iLast = iMiddle - 1;
}
}
}
else
{
retValue = true;
}

return retValue;
}

private string Soundex(string strString)
{
int i;
string strLetter;
string strCode;
string strSoundex = "";

strSoundex = String.UCase(String.Left(strString, 1));

for (i = 2; i <= String.Len(strString); i++)
{
strLetter = String.UCase(String.Mid(strString, i, 1));
switch (strLetter)
{
case "B":
case "P":
strCode = "1";
break;
case "F":
case "V":
strCode = "2";
break;
case "C":
case "K":
case "S":
strCode = "3";
break;
case "G":
case "J":
strCode = "4";
break;
case "Q":
case "X":
case "Z":
strCode = "5";
break;
case "D":
case "T":
strCode = "6";
break;
case "L":
strCode = "7";
break;
case "M":
case "N":
strCode = "8";
break;
case "R":
strCode = "9";
break;
default:
strCode = "";
break;
}

if (String.Right(strSoundex, 1) != strCode)
{
strSoundex = strSoundex + strCode;
}
}

return strSoundex;
}

private int WordSimilarity(string strWord, string strSimilarWord)
{
int functionReturnValue = 0;
int intWordLen;
int intSimilarWordLen;
int intMaxBonus;
int intPerfectValue;
int intSimilarity;
int i;

intWordLen = String.Len(strWord);
intSimilarWordLen = String.Len(strSimilarWord);

intMaxBonus = 3;
intPerfectValue = intWordLen + intWordLen + intMaxBonus;
intSimilarity = intMaxBonus - Abs(intWordLen - intSimilarWordLen);

for (i = 1; i <= intWordLen; i++)
{
if (i <= intSimilarWordLen)
{
if (String.LCase(String.Mid(strWord, i, 1)) == String.LCase(String.Mid(strSimilarWord, i, 1)))
{
intSimilarity = intSimilarity + 1;
}

if (String.LCase(String.Mid(strWord, intWordLen - i + 1, 1)) == String.LCase(String.Mid(strSimilarWord, intSimilarWordLen - i + 1, 1)))
{
intSimilarity = intSimilarity + 1;
}
}
}

functionReturnValue = intSimilarity / intPerfectValue;

return functionReturnValue;
return functionReturnValue;
}

private string[] Suggest(string strWord)
{
string[] functionReturnValue = null;
string strSoundex = "";
int i = 0;
string strSuggestions = "";
int intMaxSuggestions = 0;
int intSuggestionCount = 0;
string strSuggestion = "";
string[] strSuggestionArray;
double[] dblSimilarityArray;
double dblSimilarity = 0;

intMaxSuggestions = 10;
strSoundex = Soundex(strWord);

while (i <= Information.UBound(strDictArray))
{
if (Strings.LCase(Strings.Left(strDictArray(i), 1)) != Strings.LCase(Strings.Left(strWord, 1)))
{
i = i + 1;
}
else
{
break; // TODO: might not be correct. Was : Exit Do
}
}

while (i <= Information.UBound(strDictArray))
{
if (Strings.LCase(Strings.Left(strDictArray(i), 1)) == Strings.LCase(Strings.Left(strWord, 1)))
{
if (Soundex(strDictArray(i)) == strSoundex)
{
if (strSuggestions + "" == "")
{
strSuggestions = strDictArray(i);
}
else
{
strSuggestions = strSuggestions + "|" + strDictArray(i);
}
}
i = i + 1;
}
else
{
break; // TODO: might not be correct. Was : Exit Do
}
}

functionReturnValue = Strings.Split(strSuggestions, "|");

if (Information.UBound(functionReturnValue) < intMaxSuggestions)
{
intSuggestionCount = Information.UBound(functionReturnValue);
}
else
{
intSuggestionCount = intMaxSuggestions - 1;
}
// ERROR: Not supported in C#: ReDimStatement
// ERROR: Not supported in C#: ReDimStatement

foreach ( strSuggestion in functionReturnValue)
{
dblSimilarity = WordSimilarity(strWord, strSuggestion);
i = intSuggestionCount;
while (dblSimilarity > dblSimilarityArray(i))
{
if (i < intSuggestionCount)
{
strSuggestionArray(i + 1) = strSuggestionArray(i);
dblSimilarityArray(i + 1) = dblSimilarityArray(i);
}
strSuggestionArray(i) = strSuggestion;
dblSimilarityArray(i) = dblSimilarity;
i = i - 1;
if (i == -1)
{
break; // TODO: might not be correct. Was : Exit Do
}
}
}

functionReturnValue = strSuggestionArray;

return functionReturnValue;
return functionReturnValue;
}
}


if possible u can help me

This is regarding spellcheck
AnswerRe: Error:Cannot convert type string to int Pin
N a v a n e e t h4-Jul-08 1:13
N a v a n e e t h4-Jul-08 1:13 
QuestionJavascript for Space validation ? Pin
Masood Kochi,SSF3-Jul-08 19:47
Masood Kochi,SSF3-Jul-08 19:47 
AnswerRe: Javascript for Space validation ? Pin
Sherin Iranimose3-Jul-08 20:21
Sherin Iranimose3-Jul-08 20:21 
GeneralThanks for ur solution Pin
Masood Kochi,SSF3-Jul-08 20:36
Masood Kochi,SSF3-Jul-08 20:36 
AnswerRe: Javascript for Space validation ? Pin
N a v a n e e t h4-Jul-08 1:14
N a v a n e e t h4-Jul-08 1:14 
GeneralRe: Javascript for Space validation ? Pin
Sherin Iranimose4-Jul-08 1:42
Sherin Iranimose4-Jul-08 1:42 
QuestionActiveX Pin
Member 47748683-Jul-08 19:05
Member 47748683-Jul-08 19:05 
Questionwebconfig values into dropdownlistbox? [modified] Pin
Member 38798813-Jul-08 18:51
Member 38798813-Jul-08 18:51 
AnswerRe: webconfig values into dropdownlistbox? Pin
Francofu3-Jul-08 19:28
Francofu3-Jul-08 19:28 
GeneralRe: webconfig values into dropdownlistbox? Pin
Member 38798813-Jul-08 19:41
Member 38798813-Jul-08 19:41 
GeneralRe: webconfig values into dropdownlistbox? Pin
Member 38798813-Jul-08 19:50
Member 38798813-Jul-08 19:50 
GeneralRe: webconfig values into dropdownlistbox? Pin
Sherin Iranimose3-Jul-08 19:57
Sherin Iranimose3-Jul-08 19:57 
GeneralRe: webconfig values into dropdownlistbox? Pin
Member 38798813-Jul-08 20:04
Member 38798813-Jul-08 20:04 
GeneralRe: webconfig values into dropdownlistbox? Pin
Sherin Iranimose3-Jul-08 20:10
Sherin Iranimose3-Jul-08 20:10 
GeneralRe: webconfig values into dropdownlistbox? Pin
Sherin Iranimose3-Jul-08 20:16
Sherin Iranimose3-Jul-08 20:16 
QuestionFormat strings for editable Grid in asp.net Pin
satsihreddy843-Jul-08 18:50
satsihreddy843-Jul-08 18:50 
Questionhow to Deploying multiple web applications with VS 2005 Pin
Siva193-Jul-08 18:33
Siva193-Jul-08 18:33 

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.