Sunday 30 March 2014

COLOR CODE CALENDAR EVENTS IN SHAREPOINT


SharePoint calendars can be hard to read when all of the events are the same color. A simple no-code solution is to use multiple views. This blog post will describe the steps, in detail, of how to create a SharePoint 2013 calendar with multiple colors, for your viewing pleasure.
Create column
The first step is to create an additional column for your calendar. This column should be something you use to separate your events from one another. In this calendar I will use Conference Rooms. You might need a calendar to book your conference room usage in your company, but when you look at an overview of the calendar you cannot tell which room is being used without looking more into each event.

Color Code Calendar Events in SharePoint

On the top left of your calendar select CALENDAR and to the far right select List Settings.


Color Code Calendar Events in SharePoint
Scroll down a little and under Columns select Create Column.

Color Code Calendar Events in SharePoint
Enter in the name of your column and select Choice.

Color Code Calendar Events in SharePoint
Select the settings that you wish to apply to this column and type in each conference room name that you would like for this calendar. Select OK to create the column. Do not select Enforce unique values.

CREATE VIEWS

Next you will need to create a view for each conference room. These views will later be overlapped on one another. A view should be created for each conference room you would like to use.
Color Code Calendar Events in SharePoint

Create a View.

Color Code Calendar Events in SharePoint
Select Calendar View

Color Code Calendar Events in SharePoint

Type the conference room name as the view name.

Color Coded Calendar Events in SharePoint

Add a filter to the view. Select OK. Repeat the steps for each conference room. So I will now create a view for Lincoln Room, Pentagon Area, Summit 7 Building, and Area 51. The next step is to add the colors.
Overlap
Once all of your views are complete you will need to use the overlap function to create one view with multiple colors for each event. Once complete you should be able to select the drop-down for Current View and see all of your views.

Color Code Calendar Events in SharePoint

Under Default select Calendar. You will then proceed to add all of the views to the default view using Calendars Overlay.

Color Code Calendar Events in SharePoint
Select Calendars Overlay
Color Code Calendar Events in SharePoint
Add a New Calendar
Color Code Calendar Events in SharePoint

Type in the name of the conference room as the Calendar Name. Type in a description. Select a Color and Select Resolve to fill in the List and List View drop downs. Select the Calendar you have created all the views for as the List. Select the List View that is the same as the Calendar Name. This will need to be repeated for each conference room.

Color Code Calendar Events in SharePoint

Once complete you should see all of your conference rooms here as New Calendars. Select OK.
Filter
The last step is to filter out duplicate entries. When you create an event on your default calendar now one event will be created for the specific conference room you select and another event will be created on the default calendar because they are overlapped. To make sure duplicate events do not appear you will need to filter out all the events for the default calendar.

Color Code Calendar Events in SharePoint
Select Modify View
Color Code Calendar Events in SharePoint

Filter out all events that do not have a Conference room selected by leaving the equal to blank.
Add events
Go back to the default calendar view and start adding events. Select The Conference Room the event is being held in and save it. You will notice the event will not be color coded and your calendar should look similar to this after adding events.

Color Code Calendar Events in SharePoint

This method can be used with more than just conference rooms. Some examples would be a work schedule for specific people. You can create views and select a color for each person. You can use it for specific clients. The only downfall to this approach is the amount of colors available and the setup time it takes.
Hope you find this useful!

Monday 24 March 2014

How to get Raw HTML from a Page : System.Net.WebResponse

Retrieving a page's HTML can sometimes be necessary in applications. You could be filling columns for actual meta data of sites or may retrieving remote web sites for specific content. It's require very simple code to do all the stuff

// pass the site URL
string strHTML = Strip(Request(strWebURL + "/" + file.Url, "GET"));

//The Request Function
String Request(String uri, String verb)       {

            WebRequest request = WebRequest.Create(uri);
            request.ContentType = "application/x-www-form-urlencoded";
            request.Method = verb;
            request.ContentLength = 0;
            WebResponse response = request.GetResponse();
            if (response == null)
            return null;
            StreamReader reader = new StreamReader(response.GetResponseStream());
            return reader.ReadToEnd().Trim();
        }

// The Strip function, to remove style, scripts & Html tags from the text

 public string Strip(string text)
        {
            text = Regex.Replace(text, "", "", RegexOptions.Singleline | RegexOptions.IgnoreCase);
            text = Regex.Replace(text, "", "", RegexOptions.Singleline | RegexOptions.IgnoreCase);
            text = Regex.Replace(text, @"<(.|\n)*?>", string.Empty);
            text = text.Replace("\r\n\t", " ").Replace("\n", " ").Replace("\r", " ").Replace("\t", " ");
            return text;
        }

// That's All

How to programmatically determine customized pages in a site in SharePoint 2013


What happens when the need is to determine programmatically that a given page has been customized/ghosted or not?

We can use the "vti_hasdefaultcontent" property of the "SPFile" class to determine whether a file is customized or native.

SPFile file = SPContext.Current.Web.RootFolder.Files["default.aspx"]; 

bool IsCustomized = (bool) file.Properties["vti_hasdefaultcontent"];

Friday 21 March 2014

Programmatically create a folder in a document library and in a list

Programmatically create a folder in a document library


I was able to successfully create a folder in a document library using this code:

SPList list = web.Lists.TryGetList("ListTitle");
SPFolderCollection folderColl = list.RootFolder.SubFolders;
SPFolder newFolder = folderColl.Add(FolderUrl);

FolderUrl means one of the following:
  • "/Document Library/Folder1"
    Creates a folder named “Folder1” under “Document Library”…
  • "/Document Library/Folder1/Folder11"
    Creates a folder named “Folder11” under “Folder1” in “Document Library”…
  • "/Subsite/Document Library/Folder1"
    Creates a folder named “Folder1” under “Document Library” in a sub site…
  • "/Subsite/Document Library/Folder1/Folder11" 
    Creates a folder named “Folder11” under “Folder1” in “Document Library” in a sub site… 

Here is the desired result:



Programmatically create a folder in a list

So after we can create a folder in a SharePoint document library we now can create them in SharePoint lists.

I was able to successfully create a folder in a SharePoint list using this code :

SPList list = web.Lists.TryGetList("ListTitle");
SPListItem newFolderItem = list.Items.Add(completeFolderUrl, SPFileSystemObjectType.Folder);
newFolderItem["Title"] = "TitleOfTheFolder";
newFolderItem.Update();

completeFolderUrl means one of the following:
  • "/lists/Custom List"
    The folder is created under “Custom List”…
  • "/lists/Custom List/Folder1"
    The folder is created under “Folder1” in “Custom List”…
  • "/aboutus/lists/Custom List"
    The folder is created under “Custom List” in a sub site…
  • "/aboutus/lists/Custom List/Folder1"
    The folder is created under “Folder1” in “Custom List” in a sub site…
Important: The folder didn’t create for me when my “completeFolderUrl” ended with a slash ‘/’.

This is the desired result :





Thursday 20 March 2014

Enable Calender Control in SharePoint 2013

Normally it is not activated in public site. To activat:


1. Go to Site Settings

2. Then go to Manage site features.

3. Finally activate the Team Collaboration Lists feature as shown in the image below:




4.  Finally you will see that in the tray for creating and app part.