Tuesday, August 23, 2011

Find.Execute() in MS Word 2007 gives a "The stub received bad data" error

Here is the solution
void FindAndReplace(ref Microsoft.Office.Interop.Word.Application WordApp, object FindText, object ReplaceText)
    {
      object MatchCase = true;
      object MatchWholeWord = true;
      object MatchWildCards = false;
      object MatchSoundsLike = false;
      object nMatchAllWordForms = false;
      object Forward = true;
      object Format = false;
      object MatchKashilda = false;
      object MatchDiacritics = false;
      object MatchAlefHamza = false;
      object MatchControl = false;
      object ReadOnly = false;
      object Visible = true;
      object Replace = 2;
      object Wrap = 1;

      

      object[] Parameters = new object[] { FindText, MatchCase, MatchWholeWord, MatchWildCards
                        , MatchSoundsLike, nMatchAllWordForms, Forward, Wrap
                        , Format, ReplaceText, Replace, MatchKashilda
                        , MatchDiacritics, MatchAlefHamza,MatchControl };
      WordApp.Selection.Find.GetType().InvokeMember("Execute", System.Reflection.BindingFlags.InvokeMethod, null, WordApp.Selection.Find, Parameters);      
    }

Tuesday, August 16, 2011

how to return id after insert ms sql


IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT

 

The insert satement should look something like this.

INSERT INTO TABLE (COLUMN1, COLUMN2, ...)
VALUES     (@COLUMN1,@COLUMN2, ...);
SELECT IDENTITY_COLUMN FROM TABLE WHERE (IDENTITY_COLUMN = SCOPE_IDENTITY())

Then in your code do something like this

int identity = Convert.ToInt32(TableAdapter.InsertMethod(value1, value2, value3));

 

Friday, September 24, 2010

GridView must be placed inside a form tag with runat=server

I was creating an online test and I wanted to email the test results by topic to an email distribution list. I have a panel which has two child controls, a label with an overall % correct and a gridview with percentages by topic.

A few simple lines of code would typically handle this:

string listRecipients = ConfigurationManager.AppSettings["candidateTestEmailList"].ToString();
StringBuilder sb = new StringBuilder(2000);
pnlResults.RenderControl(new HtmlTextWriter(new System.IO.StringWriter(sb)));

//---------------------------------------------------------------------
// Send to the mail handler class
//---------------------------------------------------------------------
MailHandler mh = new MailHandler();
mh.SendMail(listRecipients, "Test Results " + tbName.Text, sb.ToString());

But I was getting the error...Gridview must be placed inside a form tag with runat=server. And of course it is, and the panel and the label are not throwing a similar error. I found this nifty fix:

public override void VerifyRenderingInServerForm(Control control)
{ 
return;
}

found it here: http://blogs.x2line.com/al/archive/2004/10/08/576.aspx

Friday, August 20, 2010

Downloading Multiple Files as a Zip File Using GridView and SharpZipLib

Abstract:
Downloading files becomes a painful procedure if you have to select each individual file manually to perform the download. In this article we are going to select multiple files and download all of them as a single zip file. 

Download SharpZipLib: 

SharpZipLib is a free .NET API which is used to perform zipping operations. We will use SharpZipLib to perform the file zip.

Displaying the Files on the GridView Control: 

We have created a folder in our application called "Files" which contains several text files. The first task is to display these files in the GridView control. The implementation is shown below: 



Follow the link :http://www.highoncoding.com/Articles/597_Downloading_Multiple_Files_as_a_Zip_File_Using_GridView_and_SharpZipLib.aspx