I created a CLR user-defined function in C# for DID you mean implementation on my website and deployed the DLL in SQL Server 2008.
But the dictionary after reading the text file is returned blank.
Below is some part of the code but the problem is in reading text file:
public Spelling()
{
try
{
string fileContent = File.ReadAllText("C:/Bgtext/big.txt");
List<string> wordList = fileContent.Split('\n').ToList();
foreach (var word in wordList)
{
string trimmedWord = word.Trim().ToLower();
if (_wordRegex.IsMatch(trimmedWord))
{
if (_dictionary.ContainsKey(trimmedWord))
_dictionary[trimmedWord]++;
else
_dictionary.Add(trimmedWord, 1);
}
}
}
catch (Exception ex)
{
ex.Message.ToString();
}
}
[SqlFunction(Name = "CorrectWords", DataAccess = DataAccessKind.Read)]
public static string correctwords(string words)
{
string[] arr = words.Split(' ');
for (int i = 0; i <= arr.Length - 1; i++)
{
arr[i] = Correct(arr[i]);
}
StringBuilder correctedwords = new StringBuilder();
foreach (string value in arr)
{
correctedwords.Append(value);
correctedwords.Append(' ');
}
return correctedwords.ToString();
}
Is there any particular location where I need to put my big.txt file after deploying the DLL to SQL Server or is it a permission issue or is there some other way to read the text file?