August 29, 2012

LINQ Queries



Here are sample linq queries:
 
1) results2 = (from a in myBrandsSite.LibraryBrandDiseaseList
                where (a.LibraryID != null && 
                       a.LibraryID.ExpirationDate >= DateTime.Today && 
                       arrayBrands.Contains(a.Brand.Title))
                select a ).ToList();
 
-- Here in the above query arrayBrands is a string array with selected options and 
   (a.Brand.Title) is the option value present in a list. 
-- The above query executes and fetches all the records which are not null and not 
   expired and fetches the data which have a value.
-- The  


August 24, 2012

Working with LINQ

Definition: LINQ [Language Integrated Query] defines a set of method names (called standard query operators, or standard sequence operators), along with translation rules from so-called query expressions to expressions using these method names, lambda expressions and anonymous types. These can, for example, be used to project and filter data into arrays, enumerable classes, XML (LINQ to XML), relational databases, and third party data sources.

Sample Query

results = (from a in myBrandsSite.LibraryBrandDiseaseList
                 where (a.LibraryID != null )
                 select a
                  ).ToList();

In the above sample query, [myBrandsSite.LibraryBrandDiseaseList] is the object[EntityList] which refers all the data from the list.
After that we filter the data from the [EntityList] with a condition.which stores the filtered data in [results].

July 6, 2012

Issue with RichTextbox in SP:Modal Dialog Box


When you have a RichTextBox in your custom form which you need to display as a Sharepoint: Modal Dialog Box, some times we dont see correct rendering of the Control on the form.

Reason: This is because, the form is not having any reference to the CSS.
So to get rid of this issue, we need to add the below <Link> tags as to inherit the css classes and add the below <Body> tag for exact rendering of the controls.


<link rel="stylesheet" type="text/css" href="/_layouts/1033/styles/Themable/forms.css?rev=jBv2mfQnEZ0HhQvHMOlmFQ%3D%3D"/>

<link rel="stylesheet" type="text/css" href="/_layouts/1033/styles/Themable/search.css?rev=T%2Bhraxktc1A8EnaG5gGMHQ%3D%3D"/>

<link rel="stylesheet" type="text/css" href="/_layouts/1033/styles/Themable/corev4.css?rev=iIikGkMuXBs8CWzKDAyjsQ%3D%3D"/>

<body scroll="yes" onload="if (typeof(_spBodyOnLoadWrapper) != 'undefined') _spBodyOnLoadWrapper();">

Showing a form in Sharepoint: Modal Dialog Box


Below is the javascript code-snippet to show a custom form in Modal-dialog Box:

-- Add the code in <Script> tags
    function OpenDialog(strPageURL) {
        var dialogOptions = SP.UI.$create_DialogOptions();
        dialogOptions.url = strPageURL; // URL of the Page
        dialogOptions.width = 750; // Width of the Dialog
        dialogOptions.height = 500; // Height of the Dialog
        dialogOptions.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
to capture dialog closed event
        SP.UI.ModalDialog.showModalDialog(dialogOptions); // Open the Dialog
        return false;
    }

    function CloseCallback(result, target) {
        location.reload(true);
    }

-- Call the function as shown below
<a class="MBbuttontop" href="/Admin/SitePages/CalendarAdd.aspx" onclick="javascript:return OpenDialog('/Admin/SitePages/CalendarAdd.aspx');" target="_blank"><span>Add Calendar</span></a>

Note: So when you click on "Add Calendar" link you will shown a Modal-Dialog popup with your custom form.

March 14, 2012

After migration from MOSS 2007 to Sharepoint 2010, the month navigation wont work, the button gets disabled. This is because, the webpart is inherited from "System.Web.UI.WebControls.WebParts" Namespace, so get through this, we need to inherit our webpart in which SPCalendarview is used from "Microsoft.SharePoint.WebPartPages.WebPart" Namespace.

public class MyCalendar : Microsoft.SharePoint.WebPartPages.WebPart

Instead of

public class MyCalendar : WebPart

Copying a folder to a location as a Feature

Here, my requirement is to copy an .asmx file to IIS root folder like [C:\inetpub\wwwroot\wss\VirtualDirectories\\]....It gets copied to the location on activation and deletes the folder on deactivation.

-- Add a feature to the solution and add an event receiver to the feature with the following code below:
-----------------------------
       string strport;
        string loc = @"C:\inetpub\wwwroot\wss\VirtualDirectories\";
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            ///// Code for copying (service) folder to IIS root folder.
            string strfileloc;
           SPWeb objSPWeb = (properties.Feature.Parent as SPSite).OpenWeb();
            strport = objSPWeb.Site.Port.ToString();
          
            strfileloc = loc + strport;
            bool exists = System.IO.File.Exists(strfileloc + @"\service\GetPreferredContent.asmx");
            if (!exists)
            {
                CopyFolder(@"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES\Wipro.MyBrand.ServiceFileCopy_ServiceFolderCopying\service\", strfileloc + @"\service");
            }
            ///// Code for copying (service) folder to IIS root folder.///////
        }

static public void CopyFolder(string sourceFolder, string destFolder)
        {
            if (!Directory.Exists(destFolder))
                Directory.CreateDirectory(destFolder);
            string[] files = Directory.GetFiles(sourceFolder);
            foreach (string file in files)
            {
                string name = Path.GetFileName(file);
                string dest = Path.Combine(destFolder, name);
                File.Copy(file, dest);
            }
            string[] folders = Directory.GetDirectories(sourceFolder);
            foreach (string folder in folders)
            {
                string name = Path.GetFileName(folder);
                string dest = Path.Combine(destFolder, name);
                CopyFolder(folder, dest);
            }
        }

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            string strfileloc;
            SPWeb objSPWeb = (properties.Feature.Parent as SPSite).OpenWeb();
            strport = objSPWeb.Site.Port.ToString(); //sps.Port.ToString();
           strfileloc = loc + strport;
            bool exists = System.IO.File.Exists(strfileloc + @"\service\GetPreferredContent.asmx");
            if (exists)
            {
                File.Delete(strfileloc + @"\service\GetPreferredContent.asmx"); // For Deleting the File from the Folder
                Directory.Delete(strfileloc + @"\service"); // For Deleting the Folder
            }
        }



Item does not exist The page you selected contains an item that does not exist. It may have been deleted by another user

When you do the migration from MOSS 2007 to sharepoint 2010, and if you use spcalendarview control in your custom webpart, it gives an error saying "Item does not exist The page you selected contains an item that does not exist. It may have been deleted by another user" when you click on an created event in the calendar, this is because of the text "&ID=" appended with the DisplayFormURL mentioned for the calendar property.To get rid of this issue, just add the property for Spcalendarview "EnableV4Rendering="false"



This has to resolve the issue.

For more details on this issue, please check the following link: http://social.msdn.microsoft.com/Forums/en/sharepointdevelopment/thread/e0b5d8f8-3c35-4ede-8686-c26234e847bd

Migrate SharePoint 2010 Infopath to SharePoint Online

 Below are the steps to follow to migrate the Infopath data to SP Online.