Thursday, January 28, 2010

Custom Search Web part code for WSS 3.0

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Search;
using Microsoft.SharePoint.Search.Query;


public void keywordQueryExecute(string strQueryText) //Pass the search text here
    using (SPSite _SPSite = new SPSite("http://IP ADDRESS HERE/sites/SITE NAME HERE/"))
        using (FullTextSqlQuery _FullTextSqlQuery = new FullTextSqlQuery(_SPSite))
            _FullTextSqlQuery.StartRow = 0;
            _FullTextSqlQuery.HighlightedSentenceCount = 3;
            _FullTextSqlQuery.KeywordInclusion = KeywordInclusion.AnyKeyword;
            _FullTextSqlQuery.ResultTypes = ResultType.RelevantResults;
            _FullTextSqlQuery.RowLimit = 5000;
            _FullTextSqlQuery.TrimDuplicates = true;
            _FullTextSqlQuery.EnableStemming = false;
            _FullTextSqlQuery.IgnoreAllNoiseQuery = true;
            _FullTextSqlQuery.SiteContext = new Uri(_SPSite.Url);

            if (SPSecurity.AuthenticationMode != System.Web.Configuration.AuthenticationMode.Windows)
                _FullTextSqlQuery.AuthenticationType = QueryAuthenticationType.PluggableAuthenticatedQuery;
                _FullTextSqlQuery.AuthenticationType = QueryAuthenticationType.NtAuthenticatedQuery;

            StringBuilder sbFullTextSqlQuery = new StringBuilder(string.Empty);
            sbFullTextSqlQuery.Append("SELECT ");
            sbFullTextSqlQuery.Append(" FileExtension,Title,Description,HitHighlightedSummary,Path,Author,Size,LastModifiedTime ");
            sbFullTextSqlQuery.Append("FROM ");
            sbFullTextSqlQuery.Append(" SCOPE() ");
            sbFullTextSqlQuery.Append("WHERE ");
            sbFullTextSqlQuery.Append(" Site= ");
            sbFullTextSqlQuery.Append(" '" + _SPSite.Url.ToString() + "' ");
            sbFullTextSqlQuery.Append(" AND ");
            sbFullTextSqlQuery.Append(" ( FREETEXT (DefaultProperties, '" + strQueryText + "') ");
            sbFullTextSqlQuery.Append(" OR ");
            sbFullTextSqlQuery.Append(" CONTAINS (*, '\"" + strQueryText + "*" + "\"')) ");
            sbFullTextSqlQuery.Append(" ORDER BY ");
            string strSort = " Rank Desc";
            //sbFullTextSqlQuery.Append(" Rank Desc");

            _FullTextSqlQuery.QueryText = sbFullTextSqlQuery.ToString();
                ResultTableCollection resultTables = _FullTextSqlQuery.Execute();

                if ((int)ResultType.RelevantResults != 0)
                    ResultTable tblResult = resultTables[ResultType.RelevantResults];

                    if (tblResult.TotalRows == 0)
                        lblQueryResult.Text = "No Search Results Returned.";
                        lblQueryResult.Text = "";
            catch (Exception Ex)
                lblQueryResult.Text = Ex.Message;

public void ReadResultTable(ResultTable rt)
    // Create a DataSet and load the returned ResultTable into it.
    DataTable relResultsTbl = new DataTable();
    relResultsTbl.TableName = "Relevant Results";
    DataSet ds = new DataSet("resultsset");
    ds.Load(rt, LoadOption.OverwriteChanges, relResultsTbl);

    // Add the results to the DataGrid.

Finally the DataSet ds will have the result. You can bind to gridview or table.

Read or Write OLE File Property

Here are the steps to Read or Write the properties of files [Title, Subject, Author and Comments]

- Add reference to C:\DsoFile\dsofile.dll to your project (this is the default location)
private void Button1_Click(object sender, EventArgs e)
  //This is the PDF file we want to update.
  string strFilename = @"c:\Test.pdf";
  //Create OleDocumentProperties object.
  DSOFile.OleDocumentProperties dso = new DSOFile.OleDocumentProperties();
  dso.Open(strFilename, false, DSOFile.dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess);

  dso.SummaryProperties.Title = "Test Title";
  dso.SummaryProperties.Subject = "Test Subject";
  dso.SummaryProperties.Author = "Test Author";
  dso.SummaryProperties.Comments = "Test Comments";


If you want run the exe of this application in other system, you have to register dsofile.dll.
For that copy dsofile.dll in that system and in command prompt navigate to the directory where the dsofile.dll is present and run the regsvr32 command like below.

regsvr32 dsofile.dll

Monday, January 25, 2010

Read Value of Control which is inside iframe

var my_frame = document.getElementById("frame1");       
var framecontent = my_frame.contentWindow || my_frame.contentDocument;      
var ctrl = framecontent.document.getElementById("txtBox");      

Get CheckBox Text and Checked property using Javascript

function checkboxClick(obj) 
    var lbl = obj.nextSibling; 
    if (obj.checked) 
        alert('not checked'); 
<asp:CheckBox ID="chk" runat="server" Text="Check" 
onclick="checkboxClick(this);" />

SharePoint Site Restore from Command Prompt

Use below commands to restore sharepoint site using stsadm command.
Here I assume that backup file is stored in D drive with name backup.dat

1) CD C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN
2) stsadm.exe -o restore -url http://your site path here -filename D:\backup.dat -overwrite

After restore go to Central Administration page. In that click Application management menu. After that click Site collection Administrators which is under Sharepoint site management.

After that In primary site collection Administrator and secondary site collection administrator, you have to add the server administrator Id.

SharePoint Site Backup from Command Prompt

Use below commands to take backup of sharepoint site using stsadm command

1) CD C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN
2) stsadm.exe -o backup -url http://your site path here -filename D:\backup.dat -overwrite

So that backup file will be generated in D drive with name backup.dat

Hi Friends

This is My New Journey With Blogger.Com