A Practical Guide to SharePoint 2013

A Practical Guide to SharePoint 2013
A Practical Guide to SharePoint 2013 - Book by Saifullah Shafiq

Monday, October 16, 2006

MOSS 2007 - Creating a Site Collection

MOSS 2007 - Creating a Site Collection
I am not going into any details. If you want to learn about site collections, there are probably many other good places but if you are a beginner who have just installed MOSS 2007 and now you are looking to create a top level site in MOSS 2007, then here are the initial steps.
If you are still stuck with the MOSS installation and setup, then you may find the following post useful, it shows you how to setup MOSS from scratch. The following post also discusses the pre-requisites and places from where you can download the pre-requisites:
After the setup and configuration is complete, you will be presented with a SharePoint Central Administration screen. Your first task is to enable some important services on the server. Click on the "Operations" tab and then select "Services on server".
You will see a screen similar to the following:
Select "Single Server or Web Server for small server farms" if you are using a single machine for your deployment. Start the services shown in red boxes in the figure shown above. These services are: Office SharePoint Server Search and Windows SharePoint Services Web Application.
You can also create "Shared Services" for your farm. SharePoint will automatically create shared services for the site collection you will create but if you want to see how shared services are created then follow the instructions shown next.
Click on the "Application Management" tab and then click "Create or configure this farm's shared services" link (encircled in red in the figure shown below).
You will be presented with the following screen:
You can see in the figure above that I have already created a couple of shared services. Click on the "New SSP" link to create a new shared service, this will open a new page. Most of the fields in this page will already have been populated with default values.  Enter a name in the "SSP Name" field and select your newly created application from the "Web application" drop down. Enter your username and password in the "SSP Service Credentials".
SharePoint will automatically add a name for the database that will be created for the shared service. You can change this name if you want. You can select a database authentication method. Windows authentication is the recommended option but you can also use SQL authentication. A search database will also be created and you will have the option to rename this database. Select authentication method for this database and finally, you will have to select an index server. In my case, it is the SQL server that hosts my SharePoint DBs. If you have a separate index server, you can choose it in the "Index Server" drop down, otherwise, choose the default SQL server and click "OK".
Now, you can start creating a web application. Select "Application Management" tab and click on "Create or extend Web application".
Select "Create a new Web Application" next.
In the next screen, you will set lot of properties. Start with IIS Web Site. Create a new IIS web site, enter description in the "Description" field. Select a port other than 80 if you already have an application running on port 80. Path is auto selected and you can change the destination but I would recommend the default location to be used. Have a look at the screen below. You can copy values exactly from this screen. Use your userid and password for application pool identity. Similarly, select an authentication type for database and provide security credentials. Finally, hit OK to continue.
Now that you have created a web site, it's time to create a top level site or site collection for your portal. You can name it as "Portal" and the URL will be http://portal if you created web site on port 80. Select "Application Management" tab and then select "Create site collection" link in "SharePoint Site Management" section.

This will bring up a new page where you will have the option to select a web site. Select your newly created web application by clicking the arrow in the dropdown box.
Select "Create site at this URL:" option to create a site collection on the root of the web site you created. In this case, your final URL will look like:
and if you select "Create site under this URL" then your URL will look like: http://portal/sites/mysite.
Provide a name for primary site collection administrator. In templates, select "Corporate Intranet Site" (Click "Publishing" tab to select this template) template and click OK.
Here is how your portal site will look like:

Thursday, September 14, 2006

Text functions for "calculated" field

Q:  Is it possible to get the first letter of a column in calculated field?
Use the Left function to get the first letter.

=LEFT(Column1,1) -> This will return the first character of column1
Instructions:
Suppose you want to get the first letter of "Title" field in document library.
1. Add a new column.
2. Give a name to the new column and select "Calculated" as the type.
3. Type the following formula in the formula box:
    =Left(Title,1)
4. Keep the return data type as "Single line of text" and click "OK".

Wednesday, September 6, 2006

Fixing InfoPath Forms in Application Templates (by Bil Simser)

Many users including my students frequently ask me how to fix this issue and i always forget the URL. Googling for the following specific link always took my time so this time i have decided to post it on my blog so that next time if some one asks, it will be easier for me to point him/her in the right direction.

http://weblogs.asp.net/bsimser/archive/2005/08/09/421993.aspx (A great post from Bil Simer!!)

Regards,

-SSA

Fixing InfoPath Forms in Application Templates (by Bil Simser)

Many users including my students frequently ask me how to fix this issue and i always forget the URL. Googling for the following specific link always took my time so this time i have decided to post it on my blog so that next time if some one asks, it will be easier for me to point him/her in the right direction.

http://weblogs.asp.net/bsimser/archive/2005/08/09/421993.aspx (A great post from Bil Simer!!)

Regards,

-SSA

Creating trust relationship in Windows

SharePoint is installed in Domain1 and you want to allow Domain2 users to access SharePoint. Both domains are in different forests. The solution is to create a 1 way trust between the two domains. Domain2 should trust Domain1 which is in login forest. To learn how to create trust relationship, see the following article:

http://www.windowsnetworking.com/articles_tutorials/Creating-Trusts-Between-Forests.html

Sunday, September 3, 2006

Updating Locked Files in SharePoint (using .NET Code)

Audience: Intermediate
Keywords: SharePoint, File lock

Q: When i try to update or delete a newly inserted file using .NET code, i get an error. SharePoint keeps the file locked for editing. I try to update file in the OnInsert() function.
Yes, this is true. SharePoint keeps your file locked. Easy solution is to rename the newly inserted document and then do manipulations on it. Interestingly, SharePoint won't allow you to rename the newly inserted file. So what should you do then? Create a copy of the newly inserted document with a different name and then you can update it's metadata easily. The other solution is given below but this won't work if you are working on a machine other than the server so this one is not very helpful but I am including it here for your learning.
NOTE: This code will not work if you are trying to update/delete file from a client machine.
Try this code:

-----------
spFile = EventWeb.GetFile( EventFileUrl );
spListItem = spFile.Item;
spListItem.ListItems.List.Items.DeleteItemById(spListItem.ID);
--------------
spListItem must be defined in the declaration section of EventSink class as following:
private SPListItem spListItem = null;

Be warned that if the file is open or if you have just finished some processing on the file then SharePoint won't let you delete or update it. The file is locked by SharePoint. If you are running the application on the SharePoint machine then you can use the following code to wait for SharePoint to release the lock on the file:

 private bool IsReadyToUpdate(string sDocName)
  {
   Process [] pWord = Process.GetProcessesByName("winword");

   int i ;
   if (pWord.Length >= 1)
   {
    for (i=0;i< pWord.Length;i++)
    {
     //pWordIdea.WaitForInputIdle();
     writeToEventLog("Status: Document is being added from machine: " + pWordIdea.MachineName.ToString()); 
     if (pWordIdea.MainWindowTitle.ToString()  == sDocName + " - Microsoft Word")
     {
      writeToEventLog("Status: Document "" + sDocName + "" found to be open. Waiting for it to be closed ...");
      
      if (!pWordIdea.HasExited)
      {
       pWordIdea.WaitForExit();
      }
      
      writeToEventLog("Status: Document "" + sDocName + " " closed down.");
      break;
     
     }
     else if (pWordIdea.MainWindowTitle.ToString()  == "Document1 - Microsoft Word")
     {
      writeToEventLog("Status: Document1 found to be open. Waiting for it to be closed ...");
      //if (!pWordIdea.HasExited)
      if (!pWordIdea.HasExited)
      {
       pWordIdea.WaitForExit();
      }
      writeToEventLog("Status: Document1 closed down.");
      break;
     }
     else
     {
      pWordIdea.CloseMainWindow();
      break;
     }
    
    }
    return true;
   }
   else
   {
    return true;
   }
  }   

 
WriteToEventLog() writes message in the Windows Log file. You can replace this function with your own code.
Here is another work around for this problem:
if (listEvent.Type == SPListEventType.Insert)
{

WindowsImpersonationContext wic = WindowsIdentity.GetCurrent().Impersonate();

SPWeb web = listEvent.Site.OpenWeb();

SPFile file = null;
SPListItem item = null;

file = web.GetFile(listEvent.UrlAfter);
item = file.Item;
item.ModerationInformation.Status = SPModerationStatusType.Pending;
item.Update();

wic.Undo();

}

Following snippet was sent by a friend. It is similar to the code shown above but contains error handling as well:
SPListItem item = listEvent.Site.OpenWeb().GetFile(listEvent.UrlAfter).Item;
//I think it's not a good method using while to check locked file.
String errorMsg = "Document Locked";
while(errorMsg.IndexOf("Document Locked")!=-1 || errorMsg.IndexOf("Save Conflict")!=-1)
{
Thread.Sleep(1000);
errorMsg = "";
item = listEvent.Site.OpenWeb().GetFile(listEvent.UrlAfter).Item;
//do something
  try
  {
    //update doc right now
    item.Update();
   }
   catch(Exception e)
   {
errorMsg = e.Message;
EventLog.WriteEntry("update Item", e.Message + "||" + e.StackTrace, EventLogEntryType.Error, 1);
   }
}

-SSA

Sending an email to all members of the site using .NET code

Category: Development
Level: Beginner 
You can send an email to all members of your SharePoint site using the following code:

SPSite mySite;
SPWeb currentWeb;
mySite = new SPSite(Url); //Url contains site URL
currentWeb = mySite.OpenWeb();
string sMemberName = "";
string strSubject = "";
string strBody = "";
for (int i=0;i<currentWeb.Users.Count;i++)
{
 sMemberName = currentWeb.UsersIdea.LoginName.ToString();
 strSubject = "Testing";
 strBody = "This is a test.";
 SendMail(currentWeb,currentWeb.Users[sMemberName].ToString() , strSubject, strBody);
}
//SendMail Function
public void SendMail(SPWeb currentWeb, string _user,string strSubject, string strBody)
{
 
 MailMessage msg;
 try
 {
  SmtpMail.SmtpServer = "smtp.yourserver.com";
  msg = new MailMessage();
  msg.BodyFormat = MailFormat.Html;
  msg.From =  currentWeb.Author.Email;
  msg.Subject = strSubject;
  msg.Body = strBody;
  msg.To = currentWeb.Users[_user].Email;
  SmtpMail.Send(msg);
    
 }
 catch (Exception ex)
 {
  //Exception Handling Code ...
 }
}

--SSA