Thursday, February 5, 2009
SQL CE - NText, doesn't support more than 4000 characters
Type : System.InvalidOperationException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Message : @TextContent : String truncation: max=4000, len=27811, value='In the email Content provide the following value,.
When i am looking into this issue, i came to know, that while dealing with NText, we need to add SQLCEParameter like this, to avoid the exception, Changing the command parameters as follows, resolve the issue.
SqlCeParameter textContent;
cmdEmail.Parameters.Add("@ID", ActivityDetails.Email.ID);
cmdEmail.Parameters.Add("@CCRecipients",ActivityDetails.Email.CCRecipients);
textContent = cmdEmail.Parameters.Add("@TextContent", SqlDbType.NText);
textContent.Value = ActivityDetails.Email.TextContent;
cmdEmail.ExecuteNonQuery();
Happy Programming
Wednesday, January 7, 2009
Black Day of Indian Market - Satyam Computers Conspiracy
Whom to blame? I thinks there is a consipiracy with the company auditors also, without their knowledge this cannot happen. What's the next step of SEBI, to guard the investors money from going into the hands of these culprits.
God sake, it is important to remember that Satyam doesn't make the entire Indian Software industry, still there are good reputed companies with honest managements in this country, and this scam is not going to represent India as a whole, it just represent a individual.
Hope the Black day for investors as well as the Indian IT industry will pass soon.
Thursday, December 25, 2008
Visual Studio 2008, Intellisense not working after statment completion
When i look into the Tools->Option ->Text Editor->C# (My programming language) - The two checkbox under the statement completion, was unchecked, having checked out the two options, my intellisense starts working.
So, if you have any issues like, intellisense not working, try this approach first.
Happy Programming
Wednesday, December 17, 2008
How to read and create a temporary file from embedded resource

While I was writing the unit test for one of the scenario, where I need to get the data from a csv file from the specified path, for running my unit test. Then comes, the question - How can i add the file to the solution and the get the necessary data from the file and what are the ways? There are two options
- First mark the csv file as an embedded resource in the solution, and have a little utility to copy the file to your temp folder and get the path from there.
- Mark the csv file as an embedded resource in the solution, and then stream the file straight from the assembly.
The second option is probably preferred because you don't pick up the bottle neck of touching the disk, but unfortunately, my test method accepts the path of the file name, so i have to write a utility to read the file from the assembly, and copy it to the temp folder. Here are the steps to work it out.
To add an file as embedded resource to the project, follow the steps below.
Since the test file will be available with us, just add the file to the project, by choosing Add Existing Item menu in the right click option of the project.
After adding the project, go to the properties of the file added, In the Build Action selection embedded resource, and rebuild the project, that's it your files has been added to the project as an embedded resource.
So now how to read the embedded resource, and create a temporary file.
With the help of assembly.GetMainfestResourceStream(resourceName), you can get the resource stream and the Path.GetTempFileName(), creates a uniquely named, zero byte temporary file on the disk, and returns the full path of that file, and now write the stream to the specified path.
Below is the sample which reads the embedded resource and creates a temp file in the temporary folder.
private const string SampleFile = "TestProject.CRM.ImportData.csv";
public static string UnpackManifestResource(string resourceName, string extenstion, Assembly assemblyName)
{
// Extract the specified resource as a stream
Assembly assembly = assemblyName;
if(assemblyName == null)
assembly = Assembly.GetExecutingAssembly();
string targetPath = Path.GetTempFileName();
if (!string.IsNullOrEmpty(extenstion))
targetPath = Path.ChangeExtension(targetPath, extenstion);
using (Stream resourceStream = assembly.GetManifestResourceStream(resourceName))
{
if (resourceStream != null)
{
var readBytes = new byte[resourceStream.Length];
resourceStream.Read(readBytes, 0, (int)resourceStream.Length);
using (var outputStream = new FileStream(targetPath, FileMode.Create))
{
outputStream.Write(readBytes, 0, readBytes.Length);
}
}
}
return targetPath;
}
Monday, December 15, 2008
CDO1.2.1 throwing COMException on Outlook 2007
"Retrieving the COM class factory for component with CLSID {3FA7DEB3-6438-101B-ACC1-00AA00423326} failed due to the following error: ". When i browsed through the net, i came to know that, Beginning in Exchange 2007 Beta 2 and Outlook 2007 Beta 2, CDO 1.2.1 will no longer be provided as a part of the install of the product. As a result, there is functionality missing that many applications depend upon. CDO 1.2.1 is a package providing access to Outlook-compatible objects through a COM-based API.
So if you are using CDO library to access Outlook objects and have plans to move your application to Office 2007. You need to install the CDO 1.2.1 separately. You can dowload the CDO 1.2.1 from here
Happy programming