A Practical Guide to SharePoint 2013

A Practical Guide to SharePoint 2013
A Practical Guide to SharePoint 2013 - Book by Saifullah Shafiq
Showing posts with label sps 2003. Show all posts
Showing posts with label sps 2003. Show all posts

Monday, September 27, 2010

SPS 2003: Deleting a site completely

This is one of the most frequently asked questions. A user when tries to re-create a deleted site gets an error (Site already exists ... !!). This happens when you delete the link but do not delete the actual site. To delete the site physically, do this:

Go to your site > Site Settings > Go to Site Administration > Delete Site (Under "Management and Statistics")

To remove the link, do this:

1. Go to site directory (sites area) > Manage sites

Find your site in the list, open the context menu (click the down arrow (drop down)) and select "Delete Item".

Now, your site is deleted and you can create it again with the same name!

Regards,

-SSA

Thursday, October 29, 2009

Upgrading to SP 2010

You will see lots of links explaining this process in the near future. Here is one link that explains the upgrade process: http://technet.microsoft.com/en-us/library/ee617150(office.14).aspx

Wednesday, May 20, 2009

Small SPQuery tip (How to get rid of "Cannot complete this action" error)

You try to run an SPQuery and get a "Cannot complete this action" error. I have seen users who think it's a permissions issue and they try to use elevatedprivileges. Remember, if you get this error when running an SPQuery object,the first thing you should look for is the query itself.  Because of a small semantical mistake the query will not run and SharePoint will throw this error. These mistakes are often difficult to locate with eye. I'd suggest use a tool, such as U2U CAML builder, to construct queries. Here is an example:
 string sQuery =
                   "<BR /><Where>" +
                    "<And>" +
                      "<Eq>" +
                         "<FieldRef Name='Title' />" +
                         "<Value Type='Text'>" + sDocumentName.ToString().Trim() + "</Value>" +
                      "</Eq>" +
                      "<Eq>" +
                      "<FieldRef Name='fc5bb16d_x002d_5336_x002d_45a6_x002d_b6e5_x002d_0c9e8de73e26' />" +
                         "<Value Type='Text'>" + sActivity + "</Value>" +
                      "</Eq>" +
                    "</And" +
                   "</Where>";
This query looks fine when you see it and it should run but it won't run because it has a small error.  If you notice the closing AND tag, you'll the closing angular bracket is missing. The query will compile but SharePoint will throw an error. The "</And" should have been "</And>".


Wednesday, February 7, 2007

SPS 2003: Displaying library items for a specific time period.

I posted this as a reply to a question last year but I still find people asking the same or a similar question every now and then, therefore, I thought I should post it on the blog so that I don't have to search it everytime some one asks a similar question.
Problem: Displaying library items for a specific time period.
Scenario: Display new items in a library for 7 days. The items should disappear from the library automatically after 7 days.
Solution:
There can be several ways to do this. One way of accomplishing this is as
follows:

1. Add a new column in your library and name it as "HiddenDate".
2. Keep it invisible by clearing the "Add to default view" check box shown
at the bottom of the page.
3. Select "Date and Time" as the type.
4. Date and Time format = Date only
5. Default value = calculated value.
6. In the calculated value, enter "=Today+7"
7. Click OK to save the changes.
8. In the view where you want to see the changes, add a filter. For example,
you can add a filter in the "All Documents" view.
9. In filter section, select "Show items only when the followint is true:".
10. In the columns drop down, select "HiddenDate"
11. In the filter options (second drop down), select "is greater than or
equal to"
12. In the third text box, enter "[Today]".
13. Click OK to save changes.

Now, every time a document is added to the library, it will remain visible
for 7 days and will disappear automatically after 7 days.

You may notice that a form is shown to the user when he adds a new document.
HiddenDate field appears on this form. Because this is an optional field
therefore user can leave it as it is and click the OK button to save the
document but just imagine what will happen if the user changes the date in
this form. Your filter will not work! Therefore, it is important to hide
this field from the user. One way is to customize the document library
template in SharePoint and add the "HiddenDate" field in the template. This
way, hiddendate field will be available in all libraries created using the
new template and user will not be shown this field when he saves the
document. To see how to add a field in the template, see the following post:

/ssa/archive/2006/05/23/7487.aspx

Published Wednesday, February 07, 2007 2:37 PM by ssa

Friday, September 1, 2006

SPS 2003: "can't move focus to the control" error

Read the following article if you are receiving the "can't move focus to the control" javascript error:

http://support.microsoft.com/?kbid=831107&FR=1

You get this error when you add a new required column in your document library and try to approve an old document that already existed there before the new column was added. I noticed this problem today when i was experimenting with an automated system. The application tried to upload the document to the library and succeeded but when i went to the library and tried to approve it, i got the javascript error. The solution is to edit the document properties, fill in the required field and then approve it.

Regards,

-SSA

Monday, April 17, 2006

The "Modified" column shows the current date and time instead of the date and time that you configured in a custom program in SharePoint Portal Server 2003

"Consider the following scenario. You create a discussion board in Microsoft Office SharePoint Portal Server 2003. You run a custom program that adds discussion items to the discussion board programmatically. The custom program also configures the date and time that appear in the Modified column for the discussion items.

However, after you run the custom program, the Modified column for the discussion items shows the current date and time instead of the date and time that you configured in the custom program. "
I noticed this problem even before but couldn't find solution at that time but now Microsoft has released a KB article that gives you a solution.

Friday, October 7, 2005

SharePoint, Document Library and SQL Server (SPS 2003)

v:* { behavior: url(#default#VML) } o:* { behavior: url(#default#VML) } .shape { behavior: url(#default#VML) }

SharePoint, Document Library and SQL Server


It's been years now, SharePoint 2007 is about to appear in the market, SharePoint 2003 seems to be something that is history now (Exaggerating .). Many companies have adopted SharePoint during the last one year. Good thing is that I have seen lots of small businesses acquiring SharePoint during the last one year. SharePoint's popularity is growing day by day and it is considered to be a top level portal product.

Document Libraries are collections of files that you can share with team members on a web based on Windows SharePoint services. Want to know more about Document Libraries?? Read more about Document Libraries on this site:


This link will show you how to create and use a document library. You can extend the functionality of these document libraries by using the "Event Handler Toolkit" that can be downloaded from the Microsoft site:


Suppose, whenever a document is added in the document library, you want to store the name of the document and the time it was added, in the database. How can you do that? Why would you do that? You can capture events fired in the document library. When ever a document is added, updated, deleted, etc, you can capture the event and add your own business logic or simply capture document information and store it in the database. Why would you store document information in the database? Well, there can be many reasons. You may want to create reports for the senior management who may want to look at the documents added to the library from time to time. You may want to track the document history or you may want to add a workflow to your document library. All this can be done by using the "Event Handler Toolkit".

Before, we proceed, let me tell you the purpose of writing this. There are many excellent articles on the internet that show you how to capture document library events and do processing but still many people come to me and ask me the same question again and again and the question is related to the capturing of document information and storing it in SQL Server. Seeing the demand, I decided to write a small article that will show you how you can capture the document information in the library and store it in SQL Server. You can do so many things, for example:

  1. When a document is added, you can copy or move it to another document library.
  2. You can delete a document.
  3. You can capture document information and store it in SQL Server.
  4. You can update document information by updating the properties associated with the document.
  5. You can add workflow mechanism to your document library. For example, when a document is added to the document library, you send an email to the approver and ask him to approve the document. Document, after getting approval from approver 1, goes to approver 2 and so on.

These are only some of the important things that you can do with Document Library EventHandler. I wish I could show you all of the above in my article but unfortunately that is not possible due to shortage of time but I promise I will try my best to update this tutorial from time to time and add more content to it. In this article, we will see how you can capture document information when a document is inserted in the library and store this information in DB.

  1. Unzip the downloaded file to the root of your system drive. Zip file contains the complete source code and the installation scripts.
  2. You must create a database before you start working with the code. Open your SQL Server and create a blank database and name it as "SPSDocLibHandler".
  3. Add a table to this database. Table name is "DocInfo". Create following fields in the table:


* Please note that "id" is an identity column.

Here is the SQL script to create this table:

CREATE TABLE [dbo].[DocInfo] (
            [id] [int] IDENTITY (1, 1) NOT NULL ,
            [Name] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
            [Modified] [datetime] NULL ,
            [ModifiedBy] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
            [ApproverComments] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
            [ApprovalStatus] [int] NULL
) ON [PRIMARY]

            You will find this script in "db.sql" file that is located in the "DB" folder inside the application folder. "db.sql" file also contains the script to create a stored         procedure that will be used in our code. I would suggest that you just create the database and then run the "db.sql" file to create the required table and stored procedure     but that's up to you. You can follow the steps listed here to do it manually.

  1. Create a stored procedure called as "sp_AddDocInfo". Here is the SQL script:

CREATE PROCEDURE dbo.sp_AddDocInfo
(
            @Name varchar(50),
            @Modified datetime,
            @ApprovalStatus int,
            @ModifiedBy varchar(50),
            @ApproverComments varchar(255)

)
as

insert into DocInfo values (@Name,@Modified,@ModifiedBy,@ApproverComments,@ApprovalStatus)

  1. There is a file called as "db.config" in the root of the application folder. This one line configuration file contains connection string to your SQL Server. Edit this file in your notepad and add your SQL Server connection details.

Data Source = YourSQLServerName (Replace this with your SQL Server's name)
Initial Catalog = SPSDocLibHandler (This is the database name)
User Id = sa (Replace this with your own user id)
Password = (Add password here, if any)

  1. Copy this file "db.config" to the root of your system drive. For example, if your system drive is "C:", copy the file to the root of "C:" drive. If your system drive is "D:" then copy the file to the root of "D:" drive.

  1. There is a file named as "Install SPSDocLibHandler.bat" in your application folder. Open this file in notepad and see if you need to make any changes. This file installs your DLL into GAC, especially check the path where gacutil.exe is located on your computer. Run this file to install DLL into GAC. You can install the assembly into GAC manually as well. "SharePoint.DocLib.Handler.dll" can be found in the "bindebug" folder inside your application folder.

  1. After installing the DLL into GAC, you need to bind your assembly to the document library where this assembly will be used. Before doing that, you also need to enable "Event Handlers" on the virtual server where your SharePoint resides. If you don't know how to do this then read this article on Microsoft's site:


For your convenience, I am listing the steps required to enable the "Event Handlers" on your virtual server.

a)      Go to SharePoint Central Administration page.


b)      Click "Configure virtual server settings from the virtual server list page" under "Portal Site and Virtual Server Configuration". This will open the "Virtual Server List" page:


c)      Click on your virtual server from the list shown on this page. Clicking on your virtual server will open the following page:


d)      Click on "Virtual server general settings" link on this page. You will see the following page:

On the bottom of the page, you will find "Event Handlers" section. Select "On" in the Event Handlers section to enable use of event handlers on the virtual server.

Now that you have enabled "Event Handlers" on your virtual server, your next step is to bind Your assembly to the document library. Following are the steps required to accomplish this:

a)      From a view of the document library to which you want to attach the event handler assembly, click Modify settings and columns.


b)      Click "Change advanced settings" on the page that opens for customizing the document library.

c)      On the Document Library Advanced Settings page, type the strong name for the assembly in the Assembly Name box. In our case assembly name box would contain:
SharePoint.DocLib.Handler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=32bb15c33a2f8eca.

You can get the values used in the strong name by right-clicking the DLL of your assembly in the Local_Drive:WINDOWSassembly directory and then clicking Properties on the shortcut menu.

d)      Type the fully qualified, case-sensitive name of the class in the Class Name box, which in this case is SharePoint.DocLib.Handler.LibraryEventSink

e)      Reset IIS by typing iisreset at a command prompt.

  1. You are now ready to test the application. Insert a document in your library and then go to your SQL Server, open the table and you will see the details of the newly added document. You can create reports based on the data in this table for the senior management. This is just one example of what you can do with SharePoint Document Libraries and the "Event Handler Toolkit".

Code Discussion

Now, let's spend a few minutes to see the application code:

Following files have been taken from the "Event Handler Toolkit":

a)      BaseEventSink.cs
b)      LoggerEventSink.cs
c)      SPListEventArgs.cs
d)      LibraryEventSink.cs

We will not discuss these files. If you want more information about how to use the "Event Handler Toolkit", read following detailed article on Microsoft's site:


We added our code in "LibraryEventSink" class. Let's take a look!

private void OnInsert()
{
     try
     {
           spFile = EventWeb.GetFile( EventFileUrl );
               
           if (spFile.Exists)
           {
                spListItem = spFile.Item;
               
                //Retrieve Database string from config file
                string strDB;
                StreamReader sr = new StreamReader(@"C:db.config");
               
                strDB = sr.ReadLine();
                sr.Close();
    

We write our code in "OnInsert()" because we want to capture the document information  at the time when it gets added to the library. If we wanted to capture the document when someone updated it, we would write our code in "OnUpdate()". First of all, we get the URL of the file just added to the library.

           spFile = EventWeb.GetFile( EventFileUrl );

spFile is an instance of class SPFile that represents a file in a SharePoint web site that is an item in a document library.

Next, we open the "db.config" file that contains the connection string to the SQL Server. We read the connection string into the "strDB" variable.

                // Create Instance of Connection and Command Object
                SqlConnection myConnection = new SqlConnection(strDB);
                SqlCommand myCommand = new SqlCommand("sp_AddDocInfo", myConnection);

                // Mark the Command as a SPROC
                myCommand.CommandType = CommandType.StoredProcedure;

Instances of Connection and Command objects are created. Stored procedure expects parameters that will contain the values to be added in the database. In the following piece of code, we define the parameters and assign values to them. We capture following document details:

1.       Document Name
2.       Date of Modification
3.       Approval Status
4.       Approver Comments
5.       Modified By

                // Add Parameters to SPROC
                SqlParameter pName= new SqlParameter("@Name", SqlDbType.VarChar , 50);
                pName.Value = spListItem["Name"];
                myCommand.Parameters.Add(pName);
                          
                SqlParameter pModified= new SqlParameter("@Modified", SqlDbType.DateTime, 8);
                pModified.Value = spListItem["Modified"];
                myCommand.Parameters.Add(pModified);

                SqlParameter pApprovalStatus= new SqlParameter("@ApprovalStatus", SqlDbType.Int , 4);
                pApprovalStatus.Value = spListItem["Approval Status"];
                myCommand.Parameters.Add(pApprovalStatus);
               
                SqlParameter pModifiedBy = new SqlParameter("@ModifiedBy", SqlDbType.VarChar , 50);
                pModifiedBy.Value = spListItem["Modified By"];
                myCommand.Parameters.Add(pModifiedBy);

In the following code, we use "if-else" to send proper value to the database to avoid error. If "Approver Comments" are empty, it will generate an error. It is important to tackle this situation. We check the property for the null value, in case it contains null, we add comments of our own otherwise we leave the original comments in tact. This property will always contain null because "Approver Comments" are always null when a new document is added to the library. Approver can add his/her comments only at the time of approval. I used this property thinking that I would demonstrate it's use in the "update" event.

                if (spListItem["Approver Comments"]!=System.DBNull.Value)
                {
                     SqlParameter pApproverComments = new SqlParameter("@ApproverComments", SqlDbType.VarChar , 255);
                     pApproverComments.Value = "No Comments";
                                                                                myCommand.Parameters.Add(pApproverComments);
          
                }
                else
                {
                     SqlParameter pApproverComments = new SqlParameter("@ApproverComments", SqlDbType.VarChar , 255);
                     pApproverComments.Value = spListItem["Approver Comments"];
                                          myCommand.Parameters.Add(pApproverComments);
                }
    
Finally, open the connection, execute the stored procedure and close the connection.

                // Open the connection and execute the Command
                myConnection.Open();
                myCommand.ExecuteNonQuery();
                myConnection.Close();

          }
                         
}

You can catch exceptions using "try-catch". Exceptions caught are logged in the Windows Event Log.

catch( System.Security.SecurityException ex )
{
          message = "Error: " + ex.Message;
          writeToEventLog(message + ":" + ex.ToString());
}
catch( Exception ex )
{
          Message = "Error: " + ex.Message;
          writeToEventLog(message + ":" + ex.ToString());
}
}

Conclusion

Some people will find this tutorial to be very simple while others may find it very complicated. To be honest, it will be complicated for the beginners but those who have lot of experience in SharePoint will find it to be simple. Well, my objective was to explain the process to the people who form the "beginner" class. You might find some errors including typos in the tutorial because it was written hastily. If you get stuck some where and need my assistance then write to me at share.point@yahoo.com or ss_ahmed1@hotmail.com. Although it is not possible to reply to each and every email but I will try my best to answer as many queries as possible. Even though I have stopped authoring tutorials for the last 2-3 years, still I get 30-40 emails daily from people who read and appreciate my tutorials, who read and criticize my work and from people who ask me to help them on their personal projects.

Please stay connected, the next tutorial in this series will be more advanced and will tell you more about the advantages of capturing documents in SharePoint Document Libraries offer.

Good Luck.

S.S. Ahmed

Thursday, September 1, 2005

SPS 2003: How to access users in members web part?

SharePoint Tip


Audience: Beginners

Question: Members web part shows all the users in my site but when i click a user to see details, it asks for a password and after i enter my username and password, i am refused access to the user details. Why? I have admin rights in the site.
You must have at least "Reader" rights on the portal. It doesn't matter if you have admin rights in the site itself but if you dont have rights at the portal level, then you can not see user details in the members web part. Clicking on a user in the members webpart takes you to the personal site (public view) of that user and if you dont have atleast "Reader" rights on the portal then you can not access the personal site of any user. This question is frequently asked by new SharePoint users so next time, if you face this situation, ask you SharePoint administrator to give you rights at the portal level.



Good luck

-SSA


Monday, August 1, 2005

SPS 2003: Use FrontPage Themes in SharePoint Sites

You may have applied themes to the SharePoint sites before. It is important because you can give a different look and feel to the sites belonging to different departments. Some groups of users like colorful sites. SharePoint contains a list of excellent themes that one can use but did you know that you can use FrontPage themes in SharePoint sites? FrontPage has an excellent collection of themes and you can use those themes for your SharePoint sites.


1. Open your SharaPoint site in FrontPage.


2. Select Format > Theme.


3. Select a theme from the collection (Click the down arrow to see options).


4. From the context menu, select "Apply as default theme".


5. A warning message will be displayed, click "Yes".


6. Check your site in browser.


-SSA