<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7507779940608001512</id><updated>2024-10-03T05:42:36.832-07:00</updated><title type='text'>SharePoint Chic</title><subtitle type='html'>I learned SharePoint development partially by reading blog posts. I would like to use this blog to share some neat tricks that I have figured out with the SharePoint developer community.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://sharepointchic.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7507779940608001512/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://sharepointchic.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>merjill</name><uri>http://www.blogger.com/profile/07714317400006005999</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7507779940608001512.post-9169733879567023477</id><published>2011-12-14T10:50:00.000-08:00</published><updated>2011-12-14T10:50:18.618-08:00</updated><title type='text'>Embed Video in SharePoint blog</title><content type='html'>The rich text editor in the SharePoint blog strips out any HTML that isn&#39;t an image or anchor tag. My client wants to embed video in a blog post using an &amp;lt;EMBED&amp;gt; tag: &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;span style=&quot;background-color: #f4cccc;&quot;&gt;&amp;lt;EMBED src=http://intranet.companyname.com/styles/CompanynameMediaPlayer.swf width=640 height=384 type=application/x-shockwave-flash FlashVars=&quot;values=&lt;/span&gt;&lt;span style=&quot;background-color: yellow; color: #444444;&quot;&gt;rtmpt://companyname.fcod.llnwd.net/a629/o1/int/IIG/IRPS/ibts_technology_123112_fk?ip=192.175.160.0/19&amp;amp;amp;&lt;/span&gt;&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;h=cd7aac23fc8643ff6f299e5e178bf7a7&amp;amp;amp;amp;autoPlay=true&amp;amp;amp;amp;skinName=http://intranet.companyname.com/styles/CompanynameMediaPlayerSkinAS3.swf&amp;amp;amp;amp;playVideoButton=true&amp;amp;amp;amp;hideFSButton=true&quot; allowScriptAccess=&quot;always&quot;&amp;gt;&amp;lt;/EMBED&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;The highlighted text above shows the actual location of the video.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;However SharePoint will allow a &amp;lt;video&amp;gt; tag because it isn&#39;t valid HTML.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;I enter the video into the blog post in this format:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;lt;video&amp;gt;&lt;span style=&quot;background-color: yellow; color: #444444;&quot;&gt;rtmpt://companyname.fcod.llnwd.net/a629/o1/int/IIG/IRPS/ibts_technology_123112_fk?ip=192.175.160.0/19&amp;amp;amp;&lt;/span&gt;&amp;lt;/video&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;&lt;span style=&quot;font-family: inherit; font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: Times, &amp;quot;Times New Roman&amp;quot;, serif; font-size: small;&quot;&gt;So I created a jquery script that would replace the opening &amp;lt;video&amp;gt;&amp;nbsp;tag with the text highlighted in pink above, and replace the &amp;lt;/video&amp;gt; tag with the text highlighted in green above.&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;strong&gt;How to implement the solution:&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;1. Create a document library on your site for scripts.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;2. Upload a Jquery library to the scripts library.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;3. Edit the following code in Notepad:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;&lt;div&gt;&amp;lt;script type=&quot;text/javascript&quot; src=&quot;&lt;a href=&quot;http://companyname.com/irps/home/video/Scripts/jquery.min.js%22%3E%3C/script&quot;&gt;&lt;span class=&quot;ms-rteThemeBackColor-10-2&quot;&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;http://companyname.com/irps/home/video/Scripts/jquery.min.js&lt;/span&gt;&quot;&lt;/span&gt;&amp;gt;&amp;lt;/script&lt;/a&gt;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;&lt;br /&gt;
$().ready(function() {&lt;/div&gt;&lt;div class=&quot;ms-rteElement-H3&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&amp;nbsp;$(&quot;.ms-PostBody&quot;).html(function(index, oldHtml) {&lt;br /&gt;
&amp;nbsp; var matchStr =&quot;(&amp;amp;lt;video&amp;amp;gt;)(.*?)(&amp;amp;lt;/video&amp;amp;gt;)&quot;;&lt;br /&gt;
&amp;nbsp; var m = oldHtml.match(matchStr);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;$.each(m, function (index, value) {&lt;br /&gt;
&amp;nbsp; var regexp1 = new RegExp(&quot;(&amp;amp;lt;video&amp;amp;gt;)&quot;);&lt;br /&gt;
&amp;nbsp; var regexp2 = new RegExp(&quot;(&amp;amp;lt;/video&amp;amp;gt;)&quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; oldHtml = oldHtml.replace(value, value.replace(regexp1, &#39;&amp;lt;embed src=http://intranet.companyname.com/styles/CompanyNameMediaPlayer.swf width=640 height=384 type=application/x-shockwave-flash Flashvars=&quot;values=&#39;).replace(regexp2, &#39;autoplay=true&amp;amp;amp;skinName=http://intranet.companyname.com/styles/CompanynameMediaPlayerSkinAS3.swf&amp;amp;amp;playVideoButton=true&amp;amp;amp;hideFSButton=true&quot; allowScriptAccess=&quot;always&quot;&amp;gt;&amp;lt;/embed&amp;gt;&#39;));&lt;br /&gt;
&amp;nbsp; });&lt;/div&gt;&lt;div&gt;&amp;nbsp; return oldHtml;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&amp;nbsp; });&lt;br /&gt;
});&lt;br /&gt;
&lt;/div&gt;&lt;/span&gt;4. After it is uploaded, copy the URL of the Jquery library from&amp;nbsp;the&amp;nbsp;script library on your site and paste it into the area highlighted above:&lt;br /&gt;
&lt;br /&gt;
5. Save the file in Notepad as a file named videoBlog.js&lt;br /&gt;
&lt;br /&gt;
6. Upload the videoBlog.js file to your scripts document library.&lt;br /&gt;
&lt;br /&gt;
7.&amp;nbsp; Open your blog.&amp;nbsp; You need to&amp;nbsp;add content editor web parts to&amp;nbsp;two pages on your blog:&amp;nbsp; &lt;br /&gt;
&lt;a href=&quot;http://[sharepointsite].companyname.com/VideoBlog/default.aspx&quot;&gt;/VideoBlog/default.aspx&lt;/a&gt;&lt;br /&gt;
and &lt;br /&gt;
&lt;a href=&quot;http://[sharepointsite].companyname.com/VideoBlog/Lists/Posts/Post.aspx&quot;&gt;/VideoBlog/Lists/Posts/Post.aspx&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;ms-rteElement-H3&quot;&gt;Enter the following urls to put the pages into Edit mode:&lt;/div&gt;&lt;div class=&quot;ms-rteElement-H3&quot;&gt;&amp;nbsp;&lt;a href=&quot;http://[sharepointsite].vanguard.com/VideoBlog/default.aspx&quot;&gt;&lt;span style=&quot;color: #0066cc;&quot;&gt;/VideoBlog/default.aspx&lt;/span&gt;&lt;/a&gt;?ToolPaneView=2&amp;amp;PageView=Shared&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;8. Add a content editor webpart&amp;nbsp;at the bottom of the page.&amp;nbsp; &lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;9. Link to the videoBlog.js file you uploaded to the Scripts library in step 6 above. &lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;10.&amp;nbsp; Set the chrome to display none &lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;11. Save the page and repeat the steps 8-10 for the other page:&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;a href=&quot;http://[sharepointsite].vanguard.com/VideoBlog/Lists/Posts/Post.aspx&quot;&gt;&lt;span style=&quot;color: #0066cc;&quot;&gt;/VideoBlog/Lists/Posts/Post.aspx&lt;/span&gt;&lt;/a&gt;?ToolPaneView=2&amp;amp;PageView=Shared&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;strong&gt;Note:&lt;/strong&gt;&amp;nbsp; The size of the&amp;nbsp;video is hardcoded in the javascript code. &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharepointchic.blogspot.com/feeds/9169733879567023477/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharepointchic.blogspot.com/2011/12/embed-video-in-sharepoint-blog.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7507779940608001512/posts/default/9169733879567023477'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7507779940608001512/posts/default/9169733879567023477'/><link rel='alternate' type='text/html' href='http://sharepointchic.blogspot.com/2011/12/embed-video-in-sharepoint-blog.html' title='Embed Video in SharePoint blog'/><author><name>merjill</name><uri>http://www.blogger.com/profile/07714317400006005999</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7507779940608001512.post-1521445764774604569</id><published>2011-05-18T13:37:00.000-07:00</published><updated>2011-05-18T13:37:48.294-07:00</updated><title type='text'>InfoPath 2007 - Validating whether a form has been edited by another user since it has been opened</title><content type='html'>We had a requirement to prevent users from overwriting another&#39;s form. Initially I tried to automate the check-in check-out function programmatially, but I ran into some obstacles.&lt;br /&gt;
&lt;br /&gt;
It is possible to programmatically check-out the form on the form Loading event, but there is no form unloading event. If a user just closes the browser window, the form will remain checked out.&lt;br /&gt;
&lt;br /&gt;
It&#39;s possible to check in a form from a SharePoint designer workflow, so I wanted to check-in the form automatically when the item was saved, but ironically, a SharePoint designer workflow won&#39;t run on an item that is already checked out.&lt;br /&gt;
&lt;br /&gt;
So as a workaround,&amp;nbsp;instead of using checkin/checkout, I&amp;nbsp;am validating the last modified date on save. When the form is first opened, I populate the InitialLastModifiedDate. When I click the save button, I populate the CurrentModfiedDate. If the dates don&#39;t match, I raise an error.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scenario:&amp;nbsp; User 1 opens form, &lt;br /&gt;
User 2 opens form&lt;br /&gt;
User 1 saves form&lt;br /&gt;
User 2 saves form ( raise error)&lt;br /&gt;
&lt;br /&gt;
This solution requires code behind.&lt;br /&gt;
&lt;br /&gt;
First add the following fields to the main data source.&lt;br /&gt;
&lt;br /&gt;
InitialLastModified&lt;br /&gt;
CurrentLastModified&lt;br /&gt;
UpdateInitialLastModified&lt;br /&gt;
doSaveValidation&lt;br /&gt;
saveMessage&lt;br /&gt;
&lt;br /&gt;
I made the InitialLastModified, CurrentLastModified and UpdateInitialLastModified fields text fields. It&#39;s not necessary to make them date fields, a string comparison was easier for me to work with. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the saveMessage field to the form. The saveMessage will display the actual validation message.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
Add a rule to the Save button on the form. The rule will update the saveMessage (I just add a period to it), and set doSaveValidation to &quot;yes&quot;.&amp;nbsp; I only want to do the validation when saving, so the doSaveValidation doesn&#39;t get set until I click the Save button. By changing the saveMessage field, I initiate some code that runs on the saveMessage_Changed Event.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZPqDfS6uB9m1VJhpCDZ4NRYMrVSM34f0_9MtXSJUcYpy82jca6K2E9vGnRhT6lT8DJN1aoeF1MHCfmZK_LlXwUFYlEzMmkpmBNnqg4r9zoBIGzGHiGvQP8PnuD5zbwgZRqR2Qv7K1f38/s1600/rule.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;244&quot; j8=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZPqDfS6uB9m1VJhpCDZ4NRYMrVSM34f0_9MtXSJUcYpy82jca6K2E9vGnRhT6lT8DJN1aoeF1MHCfmZK_LlXwUFYlEzMmkpmBNnqg4r9zoBIGzGHiGvQP8PnuD5zbwgZRqR2Qv7K1f38/s320/rule.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
In the formloading event, initiate the fields:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;populateLastModified(strIncidentNum, &quot;/my:myFields/my:InitialLastModified&quot;);&lt;br /&gt;
                xNav.SelectSingleNode(&quot;/my:myFields/my:CurrentLastModified&quot;, this.NamespaceManager).SetValue(&quot;&quot;);&lt;br /&gt;
//I&#39;m setting the doSaveValidation to &#39;no&#39; because I don&#39;t want the validation to run until the Save button is clicked.  &lt;br /&gt;
                xNav.SelectSingleNode(&quot;/my:myFields/my:doSaveValidation&quot;, this.NamespaceManager).SetValue(&quot;no&quot;);&lt;br /&gt;
                &lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
The populateLastModified function actually does a CAML Query to get the last modified date from the SharePoint form library.  I will do another CAML query in the saveMessage_Changed event to get the currentLastModified date when the form is being saved&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;public void populateLastModified(string strIncidentNum, string xPath)&lt;br /&gt;
        {&lt;br /&gt;
            SPQuery qry = new SPQuery();&lt;br /&gt;
            qry.Query = &amp;quot;&amp;lt;Where&amp;gt;&amp;lt;Eq&amp;gt;&amp;lt;FieldRef Name=&#39;ICSIncidentNum&#39;/&amp;gt;&amp;lt;Value Type=&#39;Text&#39;&amp;gt;&amp;quot; + strIncidentNum + &amp;quot;&amp;lt;/Value&amp;gt;&amp;lt;/Eq&amp;gt;&amp;lt;/Where&amp;gt;&amp;quot;;&lt;br /&gt;
            qry.ViewFields = &amp;quot;&amp;lt;FieldRef Name=&#39;Editor&#39;/&amp;gt;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                SPContext contxt = SPContext.Current;&lt;br /&gt;
                string siteURL = contxt.Web.Url;&lt;br /&gt;
                using (SPSite site = new SPSite(siteURL))&lt;br /&gt;
                {&lt;br /&gt;
                    using (SPWeb web = site.OpenWeb())&lt;br /&gt;
                    {&lt;br /&gt;
&lt;br /&gt;
                        SPList list = web.Lists[&amp;quot;ListName&amp;quot;];&lt;br /&gt;
                        SPListItemCollection LIC = list.GetItems(qry);&lt;br /&gt;
                        // there should only be one&lt;br /&gt;
                        if (LIC.Count &amp;gt; 0)&lt;br /&gt;
                        {&lt;br /&gt;
                            SPListItem item = LIC[0];&lt;br /&gt;
                            XPathNavigator xNav = this.CreateNavigator();&lt;br /&gt;
                            xNav.SelectSingleNode(xPath, this.NamespaceManager).SetValue(item[&amp;quot;Editor&amp;quot;].ToString());&lt;br /&gt;
                        }&lt;br /&gt;
&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception ex)&lt;br /&gt;
            {&lt;br /&gt;
                logError(&amp;quot;An error occurred in populateLastModified: &amp;quot; + ex.Message);&lt;br /&gt;
            }&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
Create a validating event on the saveMessage field:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;public void saveMessage_Validating(object sender, XmlValidatingEventArgs e)&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
XPathNavigator xnav = this.CreateNavigator();&lt;br /&gt;
string initialLastModified = getfieldValue(&quot;/my:myFields/my:InitialLastModified&quot;);&lt;br /&gt;
string currentLastModified = getfieldValue(&quot;/my:myFields/my:CurrentLastModified&quot;);&lt;br /&gt;
string strIncidentNum = getfieldValue(&quot;/my:myFields/my:IncidentNum&quot;);&lt;br /&gt;
string strDoSaveValidation = getfieldValue(&quot;/my:myFields/my:doSaveValidation&quot;);&lt;br /&gt;
if (strIncidentNum != &quot;&quot; &amp;amp;&amp;amp; strDoSaveValidation == &quot;yes&quot;)&lt;br /&gt;
{&lt;br /&gt;
if (initialLastModified != currentLastModified)&lt;br /&gt;
{&lt;br /&gt;
// you can switch to another view to display an error screen and display a validation error.&lt;br /&gt;
this.ViewInfos.SwitchView(&quot;SaveConflict&quot;);&lt;br /&gt;
// switch views&lt;br /&gt;
e.ReportError(xnav, false, &quot;The incident has been saved since you opened it.&quot;, &quot;Please cancel and re-open it&quot;);&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
// passed validation&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Add a changedEvent to the saveMessage Field. This will populate the currentLastModifiedDate field and initiate the validating event on the saveMessage field.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;public void saveMessage_Changed(object sender, XmlEventArgs e)&lt;br /&gt;
{&lt;br /&gt;
// populate current LastModified&lt;br /&gt;
string strIncidentNum = getfieldValue(&quot;/my:myFields/my:IncidentNum&quot;);&lt;br /&gt;
populateLastModified(strIncidentNum, &quot;/my:myFields/my:CurrentLastModified&quot;);&lt;br /&gt;
this.CreateNavigator().SelectSingleNode(&quot;/my:myFields/my:doSaveValidation&quot;, this.NamespaceManager).SetValue(&quot;yes&quot;);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;/div&gt;I frequently use this getFieldValue function:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;private string getfieldValue(string xPath)&lt;br /&gt;
        {&lt;br /&gt;
            XPathNavigator xnDoc = this.MainDataSource.CreateNavigator();&lt;br /&gt;
            XPathNavigator xnMyField = xnDoc.SelectSingleNode(xPath, this.NamespaceManager);&lt;br /&gt;
            if (xnMyField != null)&lt;br /&gt;
            {&lt;br /&gt;
                return (string)xnMyField.ValueAs(typeof(String));&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                return string.Empty;&lt;br /&gt;
            }&lt;br /&gt;
&lt;br /&gt;
        }&lt;/div&gt;&lt;br /&gt;
There is no way to clear the error. The user will have to close and re-open the form to continue.</content><link rel='replies' type='application/atom+xml' href='http://sharepointchic.blogspot.com/feeds/1521445764774604569/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharepointchic.blogspot.com/2011/05/infopath-2007-validating-whether-form.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7507779940608001512/posts/default/1521445764774604569'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7507779940608001512/posts/default/1521445764774604569'/><link rel='alternate' type='text/html' href='http://sharepointchic.blogspot.com/2011/05/infopath-2007-validating-whether-form.html' title='InfoPath 2007 - Validating whether a form has been edited by another user since it has been opened'/><author><name>merjill</name><uri>http://www.blogger.com/profile/07714317400006005999</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZPqDfS6uB9m1VJhpCDZ4NRYMrVSM34f0_9MtXSJUcYpy82jca6K2E9vGnRhT6lT8DJN1aoeF1MHCfmZK_LlXwUFYlEzMmkpmBNnqg4r9zoBIGzGHiGvQP8PnuD5zbwgZRqR2Qv7K1f38/s72-c/rule.jpg" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7507779940608001512.post-2865730622030910782</id><published>2011-01-20T10:56:00.000-08:00</published><updated>2013-10-17T12:09:12.296-07:00</updated><title type='text'>InfoPath Error: Cannot Complete This Action. Please Try Again</title><content type='html'>I&#39;m working on an InfoPath form that has code behind. I execute a button and it is supposed to do a SharePoint CAML Query and populate some fields on the InfoPath form based on data returned from the query.&lt;br /&gt;
&lt;br /&gt;
When I click the button, I get an exception &quot;Cannot Complete This Action. Please Try Again&quot;.&amp;nbsp; I looked in the SharePoint 2007 ULS logs and I saw the following error:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;Unexpected query execution failure, error code 282. Additional error information from SQL Server is included below. &quot;The &#39;proc_GetTpWebMetaDataAndListMetaData&#39; procedure attempted to return a status of NULL, which is not allowed. A status of 0 will be returned instead.&quot; Query text (if available): &quot;{?=call proc_GetTpWebMetaDataAndListMetaData(?,&#39;ED02FBB9-7901-4CD2-9E42-7E5E1F690C37&#39;,?,NULL,1,?,?,6187)}&quot;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&amp;nbsp; &lt;br /&gt;
It turned out my CAML query was malformed. I was missing some close element tags.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
I changed &lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;lt;FieldRef Name = &quot;Title&quot;&amp;gt; &lt;/span&gt;&lt;/span&gt;to &lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;lt;FieldRef Name=&quot;Title&quot;/&amp;gt;&lt;/span&gt;&lt;/span&gt; and that resolved the problem.&lt;br /&gt;
&lt;br /&gt;
Hopefully this will help someone as the error message is pretty cryptic.</content><link rel='replies' type='application/atom+xml' href='http://sharepointchic.blogspot.com/feeds/2865730622030910782/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharepointchic.blogspot.com/2011/01/infopath-error-cannot-complete-this.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7507779940608001512/posts/default/2865730622030910782'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7507779940608001512/posts/default/2865730622030910782'/><link rel='alternate' type='text/html' href='http://sharepointchic.blogspot.com/2011/01/infopath-error-cannot-complete-this.html' title='InfoPath Error: Cannot Complete This Action. Please Try Again'/><author><name>merjill</name><uri>http://www.blogger.com/profile/07714317400006005999</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7507779940608001512.post-7294123469438735741</id><published>2011-01-04T13:09:00.000-08:00</published><updated>2011-01-04T13:09:49.364-08:00</updated><title type='text'>Boolean Search Web Part</title><content type='html'>We had a requirement to do SQL type&amp;nbsp;queries on the data in a SharePoint library.&amp;nbsp; Out of the box, SharePoint supports keyword search, but you can&#39;t specify&amp;nbsp;the column in which to search.&amp;nbsp; I&amp;nbsp;created&amp;nbsp;managed properties to allow searching in specific columns, but the advanced search screen doesn&#39;t support wildcard searches.&amp;nbsp;&amp;nbsp;In order to allow Boolean searches on specific columns with wildcards, I created a webpart to use the SharePoint&#39;s FullTextSQLQuery&amp;nbsp;search capability.&lt;br /&gt;
&lt;br /&gt;
The users wanted to be able to use a query-builder user interface - where they could select the search terms and operators with buttons.&amp;nbsp; They also wanted to be able to&amp;nbsp;enter search criteria for&amp;nbsp;any column in the library. &lt;br /&gt;
&lt;br /&gt;
I created a scope with a rule that only included the documents in a specific document library.&lt;br /&gt;
I created managed properties for each of the columns in the document library.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
In the metadata property mappings view, Central Administration &amp;gt; Shared Services Administration &amp;gt; Search Administration &amp;gt; Metadata Properties , click on Crawled Properties&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcGIjwRJ6n3UYqhEum8fzCQNIlBc6bflA8_o3Z7Y-JYiRYCCCHXlzVtPUHcwmZUqFKLLN1gE6WAkSgM8TeAzE9DgOEKlH4tIiFKZZqeTfeB0zH1ha4xwLYxPHLhjRnCn_wwquRSCcA0HQ/s1600/mp.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;67&quot; n4=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcGIjwRJ6n3UYqhEum8fzCQNIlBc6bflA8_o3Z7Y-JYiRYCCCHXlzVtPUHcwmZUqFKLLN1gE6WAkSgM8TeAzE9DgOEKlH4tIiFKZZqeTfeB0zH1ha4xwLYxPHLhjRnCn_wwquRSCcA0HQ/s400/mp.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;Make sure the included In Index column is set to Yes for each crawled property that is mapped to a managed property. &lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidi9m-P_S-4lejz7VrKeVvDfTfenNi0UWm5z48JLE9sQjgT_xEc42iosAWtPKBU3DDiGL0Zy9eKtwVxTcCrb_Up5lPVl87mCQmWvvTj6Z7ZGH28Qt6fKy-tc1yKYJZAW4vPBv5oewiz6E/s1600/aName.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;120&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidi9m-P_S-4lejz7VrKeVvDfTfenNi0UWm5z48JLE9sQjgT_xEc42iosAWtPKBU3DDiGL0Zy9eKtwVxTcCrb_Up5lPVl87mCQmWvvTj6Z7ZGH28Qt6fKy-tc1yKYJZAW4vPBv5oewiz6E/s400/aName.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;After the managed properties are set up, a full crawl of the index is required before they are searchable. &lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;There are two ways to search.&amp;nbsp; You can use the quick search at the top, or the query builder at the bottom.&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcZElwUR7APv446OZt0gFSXXkJqWxE5JlAlO5OkrWECS9rbLtuKCW1Q0WQqJtKFryaxIAuw7e7iTH7apsqjDnwaAhbEsMT79qApchpduvGnhen79590ShdQAO1IHFxY3RyNqyydbx1cL0/s1600/iwp.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;183&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcZElwUR7APv446OZt0gFSXXkJqWxE5JlAlO5OkrWECS9rbLtuKCW1Q0WQqJtKFryaxIAuw7e7iTH7apsqjDnwaAhbEsMT79qApchpduvGnhen79590ShdQAO1IHFxY3RyNqyydbx1cL0/s400/iwp.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;The search results are displayed in an SPGridView with paging:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMx1If2X7W64OsuxZnP3ww2_k0ARvtxEEFwzSmC_FX4tswTaJEQVb1e1fcAy7wSpWIi_McnSo8v_dhrWp-LfVqDCVyIT2y111tHoacWMm8cn4aRhfSRVAJu-4D8bjWHohGzaPFYvcysc8/s1600/iwpResults.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;365&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMx1If2X7W64OsuxZnP3ww2_k0ARvtxEEFwzSmC_FX4tswTaJEQVb1e1fcAy7wSpWIi_McnSo8v_dhrWp-LfVqDCVyIT2y111tHoacWMm8cn4aRhfSRVAJu-4D8bjWHohGzaPFYvcysc8/s400/iwpResults.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;The paging was tricky.&amp;nbsp; I found this little &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/5aw1xfh3.aspx&quot;&gt;nugget &lt;/a&gt;on MSDN:&amp;nbsp;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&quot;If the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.aspx&quot;&gt;GridView&lt;/a&gt;  control is bound to a data source control that does not support the paging  capability directly, or if the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.aspx&quot;&gt;GridView&lt;/a&gt;  control is bound to a data structure in code through the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.basedataboundcontrol.datasource.aspx&quot;&gt;DataSource&lt;/a&gt;  property, the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.aspx&quot;&gt;GridView&lt;/a&gt;  control will perform paging by getting all of the data records from the source,  displaying only the records for the current page, and discarding the rest. This  is supported only when the data source for the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.aspx&quot;&gt;GridView&lt;/a&gt;  control returns a collection that implements the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.collections.icollection.aspx&quot;&gt;ICollection&lt;/a&gt;  interface (including datasets).&quot;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
So every time the page index changes, the query has to be re-executed because the gridview control discards the records that aren&#39;t displayed on the current page.&lt;br /&gt;
&lt;br /&gt;
Now for some code. First I CreateChildControls.&amp;nbsp; I am also using RenderContents to add the HTML Buttons and TextArea at the bottom of the webpart.&amp;nbsp; The buttons are executing Javascript so I can add text to the search critera text area without doing a postback.&amp;nbsp; I registered the javascript. You can see more details about &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/dd584169%28v=office.11%29.aspx&quot;&gt;using javascript in a web part on MSDN&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;public class ICSSearch : System.Web.UI.WebControls.WebParts.WebPart&lt;br /&gt;
{&lt;br /&gt;
// strings&lt;br /&gt;
public string DestinationPage;&lt;br /&gt;
private const string LeftParenScriptKey = &quot;myLeftParenScriptKey&quot;;&lt;br /&gt;
//add the left paren to the text box - where the cursor is&lt;br /&gt;
//get textbox name&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
* courtesy of http://alexking.org/blog/2003/06/02/inserting-at-the-cursor-using-javascript&lt;br /&gt;
* function insertAtCursor(myField, myValue) {&lt;br /&gt;
//IE support&lt;br /&gt;
if (document.selection) {&lt;br /&gt;
myField.focus();&lt;br /&gt;
sel = document.selection.createRange();&lt;br /&gt;
sel.text = myValue;&lt;br /&gt;
}&lt;br /&gt;
else if (myField.selectionStart || myField.selectionStart == &#39;0&#39;) {&lt;br /&gt;
var startPos = myField.selectionStart;&lt;br /&gt;
var endPos = myField.selectionEnd;&lt;br /&gt;
myField.value = myField.value.substring(0, startPos)&lt;br /&gt;
+ myValue&lt;br /&gt;
+ myField.value.substring(endPos, myField.value.length);&lt;br /&gt;
} else {&lt;br /&gt;
myField.value += myValue;&lt;br /&gt;
}&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
private string EmbeddedScriptFormat = &quot;&lt;script language=&quot;javascript&quot;&gt;
&quot; +
            
            &quot; function insertAtCursor(myField, myValue) {&quot; +
            // ie support
            &quot; if(document.selection) {&quot; + 
            &quot; myField.focus(); &quot; +
            &quot; sel = document.selection.createRange();&quot; +
            &quot; sel.text = myValue; }&quot; +
            // mozilla support
             &quot;  else if (myField.selectionStart || myField.selectionStart == &#39;0&#39;) {&quot; +
             &quot;  var startPos = myField.selectionStart;&quot; +
             &quot; var endPos = myField.selectionEnd;&quot; +
             &quot; myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); &quot; +
             &quot; } else { &quot; +
             &quot; myField.value += myValue; } &quot; +
             &quot; } &quot; +
            &quot; function insertText(theText) {&quot; +
            &quot; var txtID = &#39;[queryTextClientId]&#39;; &quot; +
            &quot; var txtBox = document.getElementById(txtID);&quot; + 
            &quot; insertAtCursor(txtBox, theText); &quot; +
            &quot;}&quot; +
            &quot; function insertSelectedText() {&quot; + 
            &quot;  var selText = document.getElementById(&#39;fieldList&#39;); &quot; +
            &quot;  var txtID = &#39;[queryTextClientId]&#39;; &quot; +
            &quot;  var txtBox = document.getElementById(txtID);&quot; + 
            &quot;  insertAtCursor(txtBox, selText.value );&quot; +
            &quot; } &quot; +
            &quot;
&lt;/script&gt; &quot;;&lt;br /&gt;
&lt;br /&gt;
//labels&lt;br /&gt;
Label lblID;&lt;br /&gt;
// CompareValidator checkID;&lt;br /&gt;
Label lblName;&lt;br /&gt;
Label lblProduct;&lt;br /&gt;
Label lblModel;&lt;br /&gt;
Label lblResults;&lt;br /&gt;
&lt;br /&gt;
// Text boxes&lt;br /&gt;
TextBox cmpyName;&lt;br /&gt;
TextBox EquipID;&lt;br /&gt;
TextBox ProductID;&lt;br /&gt;
TextBox ModelID;&lt;br /&gt;
&lt;br /&gt;
TextBox queryText;&lt;br /&gt;
// Buttons&lt;br /&gt;
Button cmdSearch;&lt;br /&gt;
&lt;br /&gt;
Table table;&lt;br /&gt;
SPGridView gridView;&lt;br /&gt;
DataTable resultsDataTable;&lt;br /&gt;
DataTable dt;&lt;br /&gt;
int gridViewPageIndex =0;&lt;br /&gt;
// store the dataset between pages&lt;br /&gt;
DataTable dtPaging;&lt;br /&gt;
string strQuery;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
public ICSSearch()&lt;br /&gt;
{&lt;br /&gt;
this.PreRender += new EventHandler(ICSSearch_PreRender);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//Client Script registration event&lt;br /&gt;
private void ICSSearch_PreRender(object sender, System.EventArgs e)&lt;br /&gt;
{&lt;br /&gt;
RegisterCommonScript();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// this function will register the embedded script&lt;br /&gt;
private void RegisterCommonScript()&lt;br /&gt;
{&lt;br /&gt;
// string location = null;&lt;br /&gt;
&lt;br /&gt;
// Make sure that the script was not already added to the&lt;br /&gt;
//page.&lt;br /&gt;
EmbeddedScriptFormat = EmbeddedScriptFormat.Replace(&quot;[queryTextClientId]&quot;, queryText.ClientID);&lt;br /&gt;
ClientScriptManager csm = Page.ClientScript;&lt;br /&gt;
if (!csm.IsClientScriptBlockRegistered(LeftParenScriptKey))&lt;br /&gt;
csm.RegisterClientScriptBlock(GetType(), LeftParenScriptKey,&lt;br /&gt;
EmbeddedScriptFormat);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Here is the CreateChildControls&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;protected override void CreateChildControls()&lt;br /&gt;
{&lt;br /&gt;
//Create a table control to use for positioning the controls&lt;br /&gt;
&lt;br /&gt;
table = new Table();&lt;br /&gt;
table.Width = Unit.Percentage(100);&lt;br /&gt;
for(int i =0; i&amp;lt;10; i++)            {                TableRow row= new TableRow();                TableCell cell = new TableCell();                row.Cells.Add(cell);                table.Rows.Add(row);            }             //Create the controls for EquipmentID input          lblID = new Label();          lblID.Text = &quot;Equipment ID is:&quot;;          lblID.Width = Unit.Pixel(150);          EquipID = new TextBox();          EquipID.ID = &quot;EquipID&quot;;          //Add the controls for the EquipmentID to the table          table.Rows[0].Cells[0].Controls.Add(lblID);          table.Rows[0].Cells[0].Controls.Add(EquipID);          table.Rows[0].Cells[0].Height = Unit.Pixel(30);          //Create the controls for Company Name input.                     lblName = new Label();          lblName.Text = &quot;Company Name contains:&quot;;          cmpyName = new TextBox();          //Add the controls for the Company Name to the table          table.Rows[1].Cells[0].Controls.Add(lblName);          table.Rows[1].Cells[0].Controls.Add(cmpyName);          table.Rows[1].Cells[0].Height = Unit.Pixel(30);             // add controls for Model          lblModel = new Label();          lblModel.Text = &quot;Model is: &quot;;          ModelID = new TextBox();          ModelID.ID = &quot;Model&quot;;             // add the controls for Model to the table          table.Rows[2].Cells[0].Controls.Add(lblModel);          table.Rows[2].Cells[0].Controls.Add(ModelID);          table.Rows[2].Cells[0].Height = Unit.Pixel(30);              // add controls for Product          lblProduct = new Label();          lblProduct.Text = &quot;Product is: &quot;;          ProductID = new TextBox();          ProductID.ID = &quot;Product&quot;;              // add the controls for Product to the table          table.Rows[3].Cells[0].Controls.Add(lblProduct);          table.Rows[3].Cells[0].Controls.Add(ProductID);          table.Rows[3].Cells[0].Height = Unit.Pixel(30);           //Create the search button and add to the table control          cmdSearch = new Button();          cmdSearch.ID = &quot;cmdSearch&quot;;          cmdSearch.Click += new EventHandler(cmdSearch_Click);          cmdSearch.Text = &quot;Search Incidents&quot;;          table.Rows[4].Cells[0].Controls.Add(cmdSearch);          table.Rows[4].Cells[0].Height = Unit.Pixel(30);          //Create a label to display the search message          lblResults = new Label();          table.Rows[5].Cells[0].Controls.Add(lblResults);          table.Rows[5].Cells[0].Height = Unit.Pixel(30);                                 gridView = new SPGridView();           gridView.AutoGenerateColumns = false;                    gridView.ID = &quot;GRIDID&quot;;           gridView.AllowPaging = true;           gridView.AllowSorting = true;           gridView.PagerTemplate = null;           gridView.PageIndexChanging += new GridViewPageEventHandler(gridView_PageIndexChanging);           // table.Rows[6].Cells[0].Controls.Add(gridView);                     Label queryTextLbl = new Label();           queryTextLbl.Text = &quot;Search Criteria:&quot;;                      queryText = new TextBox();           queryText.ID = &quot;queryText&quot;;           queryText.Columns = 80;           queryText.Rows = 3;          // table.Rows[6].Cells[0].Controls.Add(queryTextLbl);          // table.Rows[7].Cells[0].Controls.Add(queryText);                      BoundField colTitle = new BoundField();           colTitle.DataField = &quot;CompanyName&quot;;           colTitle.HeaderText = &quot;Company&quot;;           gridView.Columns.Add(colTitle);            BoundField colEquip = new BoundField();           colEquip.DataField = &quot;EquipmentID&quot;;           colEquip.HeaderText = &quot;Equipment ID&quot;;           gridView.Columns.Add(colEquip);            BoundField colModel = new BoundField();           colModel.DataField = &quot;ModelNum&quot;;           colModel.HeaderText = &quot;Model&quot;;           gridView.Columns.Add(colModel);            BoundField colProduct = new BoundField();           colProduct.DataField = &quot;Product&quot;;           colProduct.HeaderText = &quot;Product&quot;;           gridView.Columns.Add(colProduct);            HyperLinkField colLink = new HyperLinkField();           colLink.HeaderText = &quot;Path&quot;;           string[] pathFields = { &quot;Path&quot; };           colLink.DataNavigateUrlFields = pathFields ;                   colLink.DataTextField = &quot;LinkText&quot;;           gridView.Columns.Add(colLink);            //Add the table to the controls collection            this.Controls.Add(table);           this.Controls.Add(gridView);           this.Controls.Add(queryTextLbl);           this.Controls.Add(queryText);           gridView.PagerTemplate = null;           base.CreateChildControls();          } &lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Here is the RenderContents:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;&lt;/div&gt;&lt;br /&gt;
Here are the actions for the Search button and the paging buttons:&lt;br /&gt;
&lt;br /&gt;
Search button:&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;void cmdSearch_Click(object sender, EventArgs e)&lt;br /&gt;
{&lt;br /&gt;
string strName = cmpyName.Text;&lt;br /&gt;
string strID = EquipID.Text;&lt;br /&gt;
string strProductID = ProductID.Text ;&lt;br /&gt;
string strModelID = ModelID.Text;&lt;br /&gt;
string strCriteria = queryText.Text;&lt;br /&gt;
/*&lt;br /&gt;
Validate that the user entered something.&lt;br /&gt;
If not, prompt the user to enter an ID or search term.&lt;br /&gt;
*/&lt;br /&gt;
if (strName == &quot;&quot; &amp;amp;&amp;amp; strID == &quot;&quot; &amp;amp;&amp;amp; strProductID == &quot;&quot; &amp;amp;&amp;amp; strModelID ==&quot;&quot; &amp;amp;&amp;amp; strCriteria==&quot;&quot;)&lt;br /&gt;
{&lt;br /&gt;
lblResults.Text = &quot;You must enter a criteria for the Search.&quot;;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
if (strCriteria == &quot;&quot;)&lt;br /&gt;
{&lt;br /&gt;
// if no criteria string was entered, use this :&lt;br /&gt;
returnResults(buildSQL(strName, strID, strModelID, strProductID));&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
returnResults(parseCriteria(strCriteria));&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
}&lt;/div&gt;Paging button:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)&lt;br /&gt;
{&lt;br /&gt;
string strName = cmpyName.Text;&lt;br /&gt;
string strID = EquipID.Text;&lt;br /&gt;
string strProductID = ProductID.Text;&lt;br /&gt;
string strModelID = ModelID.Text;&lt;br /&gt;
string strCriteria = queryText.Text;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
Validate that the user entered something.&lt;br /&gt;
If not, prompt the user to enter an ID or search term.&lt;br /&gt;
*/&lt;br /&gt;
if (strName == &quot;&quot; &amp;amp; strID == &quot;&quot; &amp;amp; strProductID == &quot;&quot; &amp;amp; strModelID == &quot;&quot;)&lt;br /&gt;
{&lt;br /&gt;
lblResults.Text = &quot;You must enter a criteria for the Search.&quot;;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
if (strCriteria == &quot;&quot;)&lt;br /&gt;
{&lt;br /&gt;
// if no criteria string was entered, use this :&lt;br /&gt;
returnResults(buildSQL(strName, strID, strModelID, strProductID));&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
returnResults(parseCriteria(strCriteria));&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
gridViewPageIndex = e.NewPageIndex;&lt;br /&gt;
gridView.DataSource = dt;&lt;br /&gt;
gridView.PagerTemplate = null;&lt;br /&gt;
gridView.DataBind();&lt;br /&gt;
gridView.PageIndex = e.NewPageIndex;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;Here is the code that builds the SQL:&lt;br /&gt;
I noticed that the wildcard characters didn&#39;t work with the CONTAINS predicate unless the term was enclosed in double quotes.&lt;br /&gt;
&lt;br /&gt;
CONTAINS(CompanyName, &#39;First*&#39;) did not work.&lt;br /&gt;
&lt;br /&gt;
CONTAINS(CompanyName, &#39;&quot;First*&quot;&#39;) did work. &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;private string buildSQL(string stName, string stID, string stModel, string stProduct)&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
//TODO add all fields on form&lt;br /&gt;
//TODO Check to see why CONTAINS isn&#39;t working for Equipment&lt;br /&gt;
&lt;br /&gt;
string BDCscopeID = &quot;Company Client Support&quot;;&lt;br /&gt;
&lt;br /&gt;
//Use the StringBuilder class for the syntax string&lt;br /&gt;
StringBuilder sbSQL = new StringBuilder();&lt;br /&gt;
sbSQL.Append(&quot;SELECT CompanyName,EquipmentID,ModelNum,Product,Path FROM Scope() WHERE (\&quot;Scope\&quot;=&#39;&quot;);&lt;br /&gt;
sbSQL.Append(BDCscopeID);&lt;br /&gt;
sbSQL.Append(&quot;&#39;)&quot;);&lt;br /&gt;
if (stName != &quot;&quot;)&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
//wildcard search doesn&#39;t work unless the search term is enclosed in double quotes! &lt;br /&gt;
sbSQL.Append(&quot; AND CONTAINS(CompanyName,&#39;\&quot;&quot;);&lt;br /&gt;
sbSQL.Append(stName);&lt;br /&gt;
sbSQL.Append(&quot;\&quot;&#39;)&quot;);&lt;br /&gt;
}&lt;br /&gt;
if (stID != &quot;&quot;)&lt;br /&gt;
{&lt;br /&gt;
sbSQL.Append(&quot; AND CONTAINS(EquipmentID,&#39;\&quot;&quot;);&lt;br /&gt;
sbSQL.Append(stID);&lt;br /&gt;
sbSQL.Append(&quot;\&quot;&#39;)&quot;);&lt;br /&gt;
}&lt;br /&gt;
if (stModel != &quot;&quot;)&lt;br /&gt;
{&lt;br /&gt;
sbSQL.Append(&quot; AND CONTAINS(ModelNum,&#39;\&quot;&quot;);&lt;br /&gt;
sbSQL.Append(stModel);&lt;br /&gt;
sbSQL.Append(&quot;\&quot;&#39;)&quot;);&lt;br /&gt;
}&lt;br /&gt;
if (stProduct != &quot;&quot;)&lt;br /&gt;
{&lt;br /&gt;
sbSQL.Append(&quot; AND CONTAINS(Product,&#39;\&quot;&quot;);&lt;br /&gt;
sbSQL.Append(stProduct);&lt;br /&gt;
sbSQL.Append(&quot;\&quot;&#39;)&quot;);&lt;br /&gt;
}&lt;br /&gt;
return sbSQL.ToString();&lt;br /&gt;
}&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Here is the code that returns the results and populates the gridview.  The library contains InfoPath forms, so I changed the URL in the search results so that it would open the form in the browser. I would like to put the search results at the bottom of the web part below the criteria builder, but the RenderContents puts everything in the bottom. I&#39;m still working on that. &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;private void returnResults(string strSQL)&lt;br /&gt;
{&lt;br /&gt;
FullTextSqlQuery sqlQuery = new FullTextSqlQuery(SPContext.Current.Site);&lt;br /&gt;
try&lt;br /&gt;
{&lt;br /&gt;
strQuery = strSQL;&lt;br /&gt;
//Specify result type to return &lt;br /&gt;
sqlQuery.ResultTypes = ResultType.RelevantResults;&lt;br /&gt;
//Specify the full text search query string&lt;br /&gt;
sqlQuery.QueryText = strSQL;&lt;br /&gt;
sqlQuery.TrimDuplicates = true;&lt;br /&gt;
//Return the search results to a ResultTableCollection        &lt;br /&gt;
ResultTableCollection results = sqlQuery.Execute();&lt;br /&gt;
//Create a ResultTable for the relevant results table&lt;br /&gt;
&lt;br /&gt;
ResultTable relResults = results[ResultType.RelevantResults];&lt;br /&gt;
&lt;br /&gt;
int x = relResults.RowCount;&lt;br /&gt;
if (x != 0)&lt;br /&gt;
{&lt;br /&gt;
resultsDataTable = new DataTable();&lt;br /&gt;
resultsDataTable.TableName = &quot;Result&quot;;&lt;br /&gt;
&lt;br /&gt;
resultsDataTable.Load(relResults, LoadOption.OverwriteChanges);&lt;br /&gt;
// walk through results table and look at the rows&lt;br /&gt;
&lt;br /&gt;
string[] cName = new String[1];&lt;br /&gt;
string equip;&lt;br /&gt;
string path;&lt;br /&gt;
string[] product = new String[1];&lt;br /&gt;
string[] modelNum = new String[1];&lt;br /&gt;
&lt;br /&gt;
dt = new DataTable();&lt;br /&gt;
&lt;br /&gt;
// read results into a datatable&lt;br /&gt;
&lt;br /&gt;
dt.Columns.Add(&quot;CompanyName&quot;);&lt;br /&gt;
dt.Columns.Add(&quot;EquipmentID&quot;);&lt;br /&gt;
dt.Columns.Add(&quot;ModelNum&quot;);&lt;br /&gt;
dt.Columns.Add(&quot;Product&quot;);&lt;br /&gt;
dt.Columns.Add(&quot;Path&quot;);&lt;br /&gt;
dt.Columns.Add(&quot;LinkText&quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
foreach (DataRow row in resultsDataTable.Rows)&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
if (row[&quot;CompanyName&quot;] != null  &amp;amp;&amp;amp; row[&quot;CompanyName&quot;] != DBNull.Value )&lt;br /&gt;
{&lt;br /&gt;
// this column returns a string array&lt;br /&gt;
cName = (string[])row[&quot;CompanyName&quot;];&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
cName[0] = String.Empty;&lt;br /&gt;
}&lt;br /&gt;
if (row[&quot;EquipmentID&quot;] == null)&lt;br /&gt;
{&lt;br /&gt;
equip = String.Empty;&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
equip = row[&quot;EquipmentID&quot;].ToString();&lt;br /&gt;
}&lt;br /&gt;
if (row[&quot;Path&quot;] == null) &lt;br /&gt;
{&lt;br /&gt;
path = String.Empty;&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
path = row[&quot;Path&quot;].ToString();&lt;br /&gt;
}&lt;br /&gt;
// this column returns a string array&lt;br /&gt;
if (row[&quot;ModelNum&quot;] != null &amp;amp;&amp;amp; row[&quot;ModelNum&quot;] != DBNull.Value)&lt;br /&gt;
{&lt;br /&gt;
modelNum = (string[])row[&quot;ModelNum&quot;];&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
modelNum[0] = String.Empty;&lt;br /&gt;
}&lt;br /&gt;
// this column returns a string array&lt;br /&gt;
if (row[&quot;Product&quot;] != null &amp;amp;&amp;amp; row[&quot;Product&quot;] != DBNull.Value)&lt;br /&gt;
{&lt;br /&gt;
product = (string[])row[&quot;Product&quot;];&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
product[0] = String.Empty;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
string currentUrl = SPContext.Current.Site.Url;&lt;br /&gt;
&lt;br /&gt;
dt.Rows.Add(cName[0], equip, modelNum[0], product[0], currentUrl + &quot;/_layouts/FormServer.aspx?XmlLocation=&quot; + path + &quot;&amp;amp;DefaultItemOpen=1&quot;, path);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
gridView.DataSource = dt.DefaultView;&lt;br /&gt;
dtPaging = dt;&lt;br /&gt;
&lt;br /&gt;
//Count the number of rows in the table; 0 = no search results&lt;br /&gt;
&lt;br /&gt;
lblResults.Text = x.ToString() + &quot; item(s) found&quot;;&lt;br /&gt;
&lt;br /&gt;
} &lt;br /&gt;
}&lt;br /&gt;
catch (Exception ex1)&lt;br /&gt;
{&lt;br /&gt;
lblResults.Text = ex1.ToString();&lt;br /&gt;
}&lt;br /&gt;
finally&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
//    sqlQuery.Dispose();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharepointchic.blogspot.com/feeds/7294123469438735741/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharepointchic.blogspot.com/2011/01/boolean-search-web-part.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7507779940608001512/posts/default/7294123469438735741'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7507779940608001512/posts/default/7294123469438735741'/><link rel='alternate' type='text/html' href='http://sharepointchic.blogspot.com/2011/01/boolean-search-web-part.html' title='Boolean Search Web Part'/><author><name>merjill</name><uri>http://www.blogger.com/profile/07714317400006005999</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcGIjwRJ6n3UYqhEum8fzCQNIlBc6bflA8_o3Z7Y-JYiRYCCCHXlzVtPUHcwmZUqFKLLN1gE6WAkSgM8TeAzE9DgOEKlH4tIiFKZZqeTfeB0zH1ha4xwLYxPHLhjRnCn_wwquRSCcA0HQ/s72-c/mp.JPG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7507779940608001512.post-2875951121626296135</id><published>2010-12-20T08:28:00.000-08:00</published><updated>2010-12-20T08:28:29.804-08:00</updated><title type='text'>Synchronize Lists in two different site collections</title><content type='html'>We had a requirement to keep 4 lists in synch. There is a list of sales regions with the name of the sales representative, sales manager, etc for each region. The same list is used by several different sites. There was a master list and 3 child lists. Every time the master list is updated, the children lists should be updated. &lt;br /&gt;
&lt;br /&gt;
The code is configurable, so additional child lists can be easily added by updating an item in a SharePoint configuration list. &lt;br /&gt;
&lt;br /&gt;
For this to work, each of the child lists should begin with the same content. &lt;br /&gt;
&lt;br /&gt;
I created an ItemEventReceiver. It will fire on the following events:&lt;br /&gt;
&lt;br /&gt;
ItemAdded&lt;br /&gt;
ItemUpdated&lt;br /&gt;
ItemDeleting&lt;br /&gt;
&lt;br /&gt;
I created a list called Configuration in the main source site. In that list I created 3 columns: Title, Value and Description&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyppKFqbQlXQNkJtBgj16pfAjXZ5lWhTmIa8KuQAFtRkfFyzD5gUrUAEuto07qFMO4kLRwRCp3PQZ0z_GvkybW0DxVGxgCYQBM8Pm2FLDBgqCa3QwOP6rcvd_l82Pp_0mFi3jlACAD-l0/s1600/config2.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;264&quot; n4=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyppKFqbQlXQNkJtBgj16pfAjXZ5lWhTmIa8KuQAFtRkfFyzD5gUrUAEuto07qFMO4kLRwRCp3PQZ0z_GvkybW0DxVGxgCYQBM8Pm2FLDBgqCa3QwOP6rcvd_l82Pp_0mFi3jlACAD-l0/s640/config2.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
As shown above, I created 3 list items: &lt;br /&gt;
&lt;br /&gt;
SynchSourceList&lt;br /&gt;
SynchDestLists&lt;br /&gt;
SynchDestSites&lt;br /&gt;
&lt;br /&gt;
Each of the destination lists have the same name, so I didn&#39;t need to list 3 separate destination list names. These three items will be read by the Item Event Receiver. &lt;br /&gt;
&lt;br /&gt;
This is the code for the ItemAdded Event:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;public override void ItemAdded(SPItemEventProperties properties)&lt;br /&gt;
{&lt;br /&gt;
// copy the list item to the other lists&lt;br /&gt;
&lt;br /&gt;
try&lt;br /&gt;
{&lt;br /&gt;
this.DisableEventFiring();&lt;br /&gt;
SPListItem SourceItem = properties.ListItem;&lt;br /&gt;
SPSecurity.RunWithElevatedPrivileges(delegate()&lt;br /&gt;
{&lt;br /&gt;
string DestURL = getConfig.getConfigValue(properties.WebUrl, &quot;SynchDestSites&quot;);&lt;br /&gt;
string DestList = getConfig.getConfigValue(properties.WebUrl, &quot;SynchDestLists&quot;);&lt;br /&gt;
string[] sites = DestURL.Split(&#39;;&#39;);&lt;br /&gt;
// foreach site in list&lt;br /&gt;
foreach (string siteName in sites)&lt;br /&gt;
{&lt;br /&gt;
using (SPSite site = new SPSite(siteName))&lt;br /&gt;
{&lt;br /&gt;
using (SPWeb destWeb = site.OpenWeb())&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
SPList SPDestList = destWeb.GetList(destWeb.ServerRelativeUrl.TrimEnd(&#39;/&#39;) + &quot;/Lists/&quot; + DestList);&lt;br /&gt;
SPListItem spListItem = SourceItem;&lt;br /&gt;
SPListItem newDestItem = SPDestList.Items.Add();&lt;br /&gt;
foreach (SPField field in spListItem.Fields)&lt;br /&gt;
{&lt;br /&gt;
if (!field.ReadOnlyField &amp;amp;&amp;amp;&lt;br /&gt;
field.Type != SPFieldType.Invalid &amp;amp;&amp;amp;&lt;br /&gt;
field.Type != SPFieldType.WorkflowStatus &amp;amp;&amp;amp;&lt;br /&gt;
field.Type != SPFieldType.File &amp;amp;&amp;amp;&lt;br /&gt;
field.Type != SPFieldType.Attachments &amp;amp;&amp;amp;&lt;br /&gt;
field.Type != SPFieldType.Computed &amp;amp;&amp;amp;&lt;br /&gt;
field.Type != SPFieldType.Lookup)&lt;br /&gt;
{&lt;br /&gt;
newDestItem[field.InternalName] = spListItem[field.InternalName];&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
newDestItem.Update();&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
});&lt;br /&gt;
base.ItemAdded(properties);&lt;br /&gt;
}&lt;br /&gt;
catch(Exception ex)&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
finally&lt;br /&gt;
{&lt;br /&gt;
this.EnableEventFiring();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
The ItemAdded Event calls GetConfigValue which is listed here:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;class getConfig&lt;br /&gt;
{&lt;br /&gt;
public static string getConfigValue(string webURL, string listItem)&lt;br /&gt;
{&lt;br /&gt;
// get the destURL and destList from the Configuration List&lt;br /&gt;
string retValue;&lt;br /&gt;
try&lt;br /&gt;
{&lt;br /&gt;
SPSite thisSite = new SPSite(webURL);&lt;br /&gt;
SPWeb thisWeb = thisSite.OpenWeb();&lt;br /&gt;
SPList configList = thisWeb.GetList(thisWeb.ServerRelativeUrl.TrimEnd(&#39;/&#39;) + &quot;/Lists/Configuration&quot;);&lt;br /&gt;
&lt;br /&gt;
SPQuery query = new SPQuery();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
query.ViewFields =&lt;br /&gt;
@&quot;&lt;fieldref name=&quot;&quot; value??=&quot;&quot;&gt;&quot;;&lt;br /&gt;
query.Query = @&quot;&lt;where&gt;&lt;eq&gt;&lt;fieldref name=&quot;&quot; title??=&quot;&quot;&gt;&lt;value text??=&quot;&quot; type=&quot;&quot;&gt;&quot; + listItem +&lt;br /&gt;
@&quot;&lt;/value&gt;&lt;/eq&gt;&lt;/where&gt;&quot;;&lt;br /&gt;
SPListItemCollection items = configList.GetItems(query);&lt;br /&gt;
&lt;br /&gt;
// just get the first item&lt;br /&gt;
SPItem firstItem = items[0];&lt;br /&gt;
retValue = firstItem[&quot;Value&quot;].ToString();&lt;br /&gt;
&lt;br /&gt;
if (thisWeb != null)&lt;br /&gt;
thisWeb.Dispose();&lt;br /&gt;
&lt;br /&gt;
if (thisSite != null)&lt;br /&gt;
thisSite.Dispose();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
catch (Exception ex)&lt;br /&gt;
{&lt;br /&gt;
System.Diagnostics.Debug.WriteLine(&quot;RegistrationListEventReceiver.ItemAdded() exception in getConfigValue&quot; + ex.ToString());&lt;br /&gt;
retValue = &quot;Error&quot;;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
return retValue;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
I am also capturing the ItemDeleting Event:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;public override void ItemDeleting(SPItemEventProperties properties)&lt;br /&gt;
{&lt;br /&gt;
// remove the list item from the other lists&lt;br /&gt;
// find the item in the other list with the same ID and delete it&lt;br /&gt;
&lt;br /&gt;
string key;&lt;br /&gt;
try&lt;br /&gt;
{&lt;br /&gt;
this.DisableEventFiring();&lt;br /&gt;
SPListItem SourceItem = properties.ListItem;&lt;br /&gt;
SPSecurity.RunWithElevatedPrivileges(delegate()&lt;br /&gt;
{&lt;br /&gt;
key = SourceItem[&quot;RecordID&quot;].ToString();&lt;br /&gt;
&lt;br /&gt;
// do a query on the destination list and get the item with the same key&lt;br /&gt;
string DestURL = getConfig.getConfigValue(properties.WebUrl, &quot;SynchDestSites&quot;);&lt;br /&gt;
string DestList = getConfig.getConfigValue(properties.WebUrl, &quot;SynchDestLists&quot;);&lt;br /&gt;
string[] sites = DestURL.Split(&#39;;&#39;);&lt;br /&gt;
&lt;br /&gt;
// for each site in list&lt;br /&gt;
foreach (string siteName in sites)&lt;br /&gt;
{&lt;br /&gt;
using (SPSite site = new SPSite(siteName))&lt;br /&gt;
{&lt;br /&gt;
using (SPWeb destWeb = site.OpenWeb())&lt;br /&gt;
{&lt;br /&gt;
SPQuery qry = new SPQuery();&lt;br /&gt;
qry.ViewFields = @&quot;&lt;fieldref name=&quot;Title&quot;&gt;&quot;;&lt;br /&gt;
qry.Query = @&quot;&lt;where&gt;&lt;eq&gt;&lt;fieldref name=&quot;RecordID&quot;&gt;&lt;value type=&quot;Text&quot;&gt;&quot; + key + &quot;&lt;/value&gt;&lt;/eq&gt;&lt;/where&gt;&quot;;&lt;br /&gt;
SPList SPDestList = destWeb.GetList(destWeb.ServerRelativeUrl.TrimEnd(&#39;/&#39;) + &quot;/Lists/&quot; + DestList);&lt;br /&gt;
SPListItemCollection items = SPDestList.GetItems(qry);&lt;br /&gt;
if (items.Count &amp;gt; 0)&lt;br /&gt;
{&lt;br /&gt;
for (int i = items.Count - 1; i &amp;gt;= 0; i--)&lt;br /&gt;
{&lt;br /&gt;
items.Delete(i);&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
);&lt;br /&gt;
base.ItemDeleting(properties);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
catch (Exception ex)&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
finally&lt;br /&gt;
{&lt;br /&gt;
this.EnableEventFiring();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;/div&gt;&lt;br /&gt;
and the ItemUpdated Event:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;public override void ItemUpdated(SPItemEventProperties properties)&lt;br /&gt;
{&lt;br /&gt;
//update the list item in the other list(s)&lt;br /&gt;
string key;&lt;br /&gt;
try&lt;br /&gt;
{&lt;br /&gt;
this.DisableEventFiring();&lt;br /&gt;
SPListItem SourceItem = properties.ListItem;&lt;br /&gt;
SPSecurity.RunWithElevatedPrivileges(delegate()&lt;br /&gt;
{&lt;br /&gt;
key = SourceItem[&quot;RecordID&quot;].ToString();&lt;br /&gt;
&lt;br /&gt;
// do a query on the destination list and get the item with the same key&lt;br /&gt;
string DestURL = getConfig.getConfigValue(properties.WebUrl, &quot;SynchDestSites&quot;);&lt;br /&gt;
string DestList = getConfig.getConfigValue(properties.WebUrl, &quot;SynchDestLists&quot;);&lt;br /&gt;
string[] sites = DestURL.Split(&#39;;&#39;);&lt;br /&gt;
// for each site in list&lt;br /&gt;
foreach (string siteName in sites)&lt;br /&gt;
{&lt;br /&gt;
using (SPSite site = new SPSite(siteName))&lt;br /&gt;
{&lt;br /&gt;
using (SPWeb destWeb = site.OpenWeb())&lt;br /&gt;
{&lt;br /&gt;
SPQuery qry = new SPQuery();&lt;br /&gt;
qry.ViewFields = @&quot;&lt;fieldref name=&quot;Title&quot;&gt;&quot;;&lt;br /&gt;
qry.Query = @&quot;&lt;where&gt;&lt;eq&gt;&lt;fieldref name=&quot;RecordID&quot;&gt;&lt;value type=&quot;Text&quot;&gt;&quot; + key + &quot;&lt;/value&gt;&lt;/eq&gt;&lt;/where&gt;&quot;;&lt;br /&gt;
SPList SPDestList = destWeb.GetList(destWeb.ServerRelativeUrl.TrimEnd(&#39;/&#39;) + &quot;/Lists/&quot; + DestList);&lt;br /&gt;
SPListItemCollection items = SPDestList.GetItems(qry);&lt;br /&gt;
foreach (SPListItem item in items)&lt;br /&gt;
{&lt;br /&gt;
//update the fields from the source item&lt;br /&gt;
foreach (SPField field in SourceItem.Fields)&lt;br /&gt;
{&lt;br /&gt;
if (!field.ReadOnlyField &amp;amp;&amp;amp;&lt;br /&gt;
field.Type != SPFieldType.Invalid &amp;amp;&amp;amp;&lt;br /&gt;
field.Type != SPFieldType.WorkflowStatus &amp;amp;&amp;amp;&lt;br /&gt;
field.Type != SPFieldType.File &amp;amp;&amp;amp;&lt;br /&gt;
field.Type != SPFieldType.Attachments &amp;amp;&amp;amp;&lt;br /&gt;
field.Type != SPFieldType.Computed &amp;amp;&amp;amp;&lt;br /&gt;
field.Type != SPFieldType.Lookup)&lt;br /&gt;
{&lt;br /&gt;
item[field.InternalName] = SourceItem[field.InternalName];&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
item.Update();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
);&lt;br /&gt;
base.ItemUpdated(properties);&lt;br /&gt;
}&lt;br /&gt;
catch (Exception ex)&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
finally&lt;br /&gt;
{&lt;br /&gt;
this.EnableEventFiring();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;/div&gt;&lt;br /&gt;
I also created a Feacture Event Receiver so that when the Feature is Activated, it would associate the Item EventReceivers with the specified sourceList. You can see the code here:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;public override void FeatureActivated(SPFeatureReceiverProperties properties)&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
try&lt;br /&gt;
{&lt;br /&gt;
using (SPSite destSite = new SPSite(&quot;http://yoursite.org&quot;))&lt;br /&gt;
{&lt;br /&gt;
using (SPWeb destWeb = destSite.OpenWeb())&lt;br /&gt;
{&lt;br /&gt;
//make this configurable&lt;br /&gt;
&lt;br /&gt;
string listName;&lt;br /&gt;
listName = SynchronizeLists.getConfig.getConfigValue(&quot;http://yoursite.org&quot;, &quot;SynchSourceList&quot;);&lt;br /&gt;
&lt;br /&gt;
destWeb.Lists[listName].EventReceivers.Add(&lt;br /&gt;
SPEventReceiverType.ItemAdded,&lt;br /&gt;
&quot;SynchronizeLists, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3900cea7f3c6a92a&quot;,&lt;br /&gt;
&quot;SynchronizeLists.SynchronizeListsItemEventReceiver&quot;);&lt;br /&gt;
destWeb.Lists[listName].EventReceivers.Add(&lt;br /&gt;
SPEventReceiverType.ItemDeleting,&lt;br /&gt;
&quot;SynchronizeLists, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3900cea7f3c6a92a&quot;,&lt;br /&gt;
&quot;SynchronizeLists.SynchronizeListsItemEventReceiver&quot;);&lt;br /&gt;
destWeb.Lists[listName].EventReceivers.Add(&lt;br /&gt;
SPEventReceiverType.ItemUpdated,&lt;br /&gt;
&quot;SynchronizeLists, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3900cea7f3c6a92a&quot;,&lt;br /&gt;
&quot;SynchronizeLists.SynchronizeListsItemEventReceiver&quot;);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
catch (Exception ex)&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
There is a FeatureDeactivating event receiver as well:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;public override void FeatureDeactivating(SPFeatureReceiverProperties properties)&lt;br /&gt;
{&lt;br /&gt;
try&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
using (SPWeb web = properties.Feature.Parent as SPWeb)&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
string listName;&lt;br /&gt;
listName = getConfig.getConfigValue(&quot;http://yoursite.org&quot;, &quot;SourceList&quot;);&lt;br /&gt;
SPList TheList = web.Lists[listName];&lt;br /&gt;
//Declare the full assembly name &lt;br /&gt;
String AssemblyName = &quot;SynchronizeLists, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3900cea7f3c6a92a&quot;;&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; TheList.EventReceivers.Count; i++) { if (TheList.EventReceivers[i].Assembly.Equals(AssemblyName)) TheList.EventReceivers[i].Delete(); } //Update the list TheList.Update(); web.Update(); } } catch (Exception ex) { } } &lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharepointchic.blogspot.com/feeds/2875951121626296135/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharepointchic.blogspot.com/2010/12/synchronize-lists-in-two-different-site.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7507779940608001512/posts/default/2875951121626296135'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7507779940608001512/posts/default/2875951121626296135'/><link rel='alternate' type='text/html' href='http://sharepointchic.blogspot.com/2010/12/synchronize-lists-in-two-different-site.html' title='Synchronize Lists in two different site collections'/><author><name>merjill</name><uri>http://www.blogger.com/profile/07714317400006005999</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyppKFqbQlXQNkJtBgj16pfAjXZ5lWhTmIa8KuQAFtRkfFyzD5gUrUAEuto07qFMO4kLRwRCp3PQZ0z_GvkybW0DxVGxgCYQBM8Pm2FLDBgqCa3QwOP6rcvd_l82Pp_0mFi3jlACAD-l0/s72-c/config2.png" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7507779940608001512.post-6805187229894028196</id><published>2010-12-16T11:06:00.000-08:00</published><updated>2010-12-16T11:07:42.935-08:00</updated><title type='text'>Input Validation for File Attachment Names</title><content type='html'>SharePoint does not allow special characters ([~#%&amp;amp;*{}&amp;lt;&amp;gt;?/+|\&quot;]) in it&#39;s attachment names.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
I had an ItemAdded&amp;nbsp;EventReceiver running on a WSS site.&amp;nbsp; And when I created an item, and added an attachment with a special character, I received&amp;nbsp;the error message: &quot;&lt;em&gt;The file or folder name contains characters that are not permitted. &amp;nbsp;Please use a different name.&lt;/em&gt; &quot;, &lt;br /&gt;
&lt;br /&gt;
But the item would get created anyway. And the EventReceiver didn&#39;t fire.&amp;nbsp; I needed to do input validation on the client side before the item was submitted.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Add a Content Editor Web Part to the NewForm.aspx. &lt;/li&gt;
&lt;ol&gt;&lt;li&gt;Create a new list item&lt;/li&gt;
&lt;li&gt;Add &amp;amp;PageView=Shared&amp;amp;ToolPaneView=2 to the end of the URL in your browser&lt;/li&gt;
&lt;li&gt;Click Add a Web Part and select Content Editor Web Part from the Miscellaneous group&lt;/li&gt;
&lt;/ol&gt;&lt;li&gt;Add the following code to the Source Editor&lt;/li&gt;
&lt;/ol&gt;&lt;div class=&quot;code&quot;&gt;&amp;lt;Script type=&quot;text/javascript&quot;&amp;gt; &lt;br /&gt;
function PreSaveAction()   &lt;br /&gt;
{     &lt;br /&gt;
var attachment;    &lt;br /&gt;
var filename=&quot;&quot;;   &lt;br /&gt;
var fileNameSpecialCharacters = new RegExp(&quot;[~#%&amp;amp;*{}&amp;lt;&amp;gt;;?/+|\&quot;]&quot;);      &lt;br /&gt;
try  {       &lt;br /&gt;
attachment = document.getElementById(&quot;idAttachmentsTable&quot;).getElementsByTagName(&quot;span&quot;)[0].firstChild;            &lt;br /&gt;
filename = attachment.data; &lt;br /&gt;
}   &lt;br /&gt;
catch (e) {  &lt;br /&gt;
}   &lt;br /&gt;
if (fileNameSpecialCharacters.test(filename)) {         &lt;br /&gt;
alert(&quot;Please remove the special characters from the file attachment name.&quot;);&lt;br /&gt;
return false; &lt;br /&gt;
} &lt;br /&gt;
else { &lt;br /&gt;
return true;     &lt;br /&gt;
} &lt;br /&gt;
} &lt;br /&gt;
&amp;lt;/script&amp;gt; &lt;/div&gt;&lt;br /&gt;
I used a javascript regular expression to check for invalid characters.&lt;br /&gt;
&lt;br /&gt;
The user is prompted to remove the special characters from the file attachment.</content><link rel='replies' type='application/atom+xml' href='http://sharepointchic.blogspot.com/feeds/6805187229894028196/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharepointchic.blogspot.com/2010/12/input-validation-for-file-attachment.html#comment-form' title='15 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7507779940608001512/posts/default/6805187229894028196'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7507779940608001512/posts/default/6805187229894028196'/><link rel='alternate' type='text/html' href='http://sharepointchic.blogspot.com/2010/12/input-validation-for-file-attachment.html' title='Input Validation for File Attachment Names'/><author><name>merjill</name><uri>http://www.blogger.com/profile/07714317400006005999</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>15</thr:total></entry></feed>