A Practical Guide to SharePoint 2013

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

Monday, August 28, 2006

SharePoint: "Cannot complete this action" error


 
If your SharePoint custom application stops working and you get "Cannot complete this action" error, then here is the solution:

http://support.microsoft.com/?id=909455

According to Microsoft, after installing WSS SP2, users will have to impersonate explicitly to avoid the error. Following are some error messages that you would get:

"Cannot complete this action."

"Microsoft.SharePoint.SPException: Cannot complete this action."

"System.Runtime.InteropServices.COMException (0x80004005): Cannot complete this action."

Detailed Error Message:

Please try again.
at Microsoft.SharePoint.Library.SPRequestInternalClass.OpenWebInternal(String bstrUrl, String& pbstrServerRelativeUrl, UInt32& pnLanguage, UInt32& pnLocale, String& pbstrAlternateCSSUrl, String& pbstrCustomJSUrl, String& pbstrAlternateHeaderUrl)
at Microsoft.SharePoint.Library.a.a(String A_0, String& A_1, UInt32& A_2, UInt32& A_3, String& A_4, String& A_5, String& A_6)
--- End of inner exception stack trace ---
at Microsoft.SharePoint.Library.a.a(String A_0, String& A_1, UInt32& A_2, UInt32& A_3, String& A_4, String& A_5, String& A_6)
at Microsoft.SharePoint.SPWeb.f()
at Microsoft.SharePoint.SPWeb.get_ServerRelativeUrl()
at Microsoft.SharePoint.SPWeb.get_Url()
at Microsoft.SharePoint.SPWeb.c(String A_0, Boolean A_1, Boolean A_2)
at Microsoft.SharePoint.SPWeb.f(String A_0)
at Microsoft.SharePoint.SPWeb.GetFile(String strUrl)
at EnPointe.SharePoint.CCM1.LibraryEventSink.OnUpdate()System.Runtime.InteropServices.COMException (0x80004005): Cannot complete this action.

Please try again.
at Microsoft.SharePoint.Library.SPRequestInternalClass.OpenWebInternal(String bstrUrl, String& pbstrServerRelativeUrl, UInt32& pnLanguage, UInt32& pnLocale, String& pbstrAlternateCSSUrl, String& pbstrCustomJSUrl, String& pbstrAlternateHeaderUrl)
at Microsoft.SharePoint.Library.a.a(String A_0, String& A_1, UInt32& A_2, UInt32& A_3, String& A_4, String& A_5, String& A_6) at Microsoft.SharePoint.Library.a.a(String A_0, String& A_1, UInt32& A_2, UInt32& A_3, String& A_4, String& A_5, String& A_6)
at Microsoft.SharePoint.SPWeb.f()
at Microsoft.SharePoint.SPWeb.get_ServerRelativeUrl()
at Microsoft.SharePoint.SPWeb.get_Url()
at Microsoft.SharePoint.SPWeb.c(String A_0, Boolean A_1, Boolean A_2)
at Microsoft.SharePoint.SPWeb.f(String A_0)
at Microsoft.SharePoint.SPWeb.GetFile(String strUrl)
at EnPointe.SharePoint.CCM1.LibraryEventSink.OnUpdate()Microsoft.SharePoint

For more information, see Help and Support Center at ...

--
SSA

  eddy writes:
4/5/2007 #
For me, it works if I impersonate as ...myself:

System.Security.Principal.WindowsImpersonationContext wic = null;
wic = System.Security.Principal.WindowsIdentity.GetCurrent().Impersonate();

SPSite site = new SPSite(...);
SPWeb web = site.OpenWeb(...);

....

wic.Undo();

Wednesday, August 16, 2006

Creating your own document library template with your own set of fields

You manage a large document management system in your organization. Your organization has many departments. You create a site for each department and each site has a document library. You add some custom fields in your library but you don't want the dialog box to pop-up asking users to enter values for the custom fields whenever they insert a new document. You may have experienced this in your company. When you add custom fields in your document or form library, a dialog box pops up every time user tries to add a new document. Suppose, the number of custom fields exceeds 10. You don't want your users to be presented with a dialog box with more than 10 fields to be filled up every time they add a file. You need to add these fields in all the document libraries in your SharePoint Portal. What do you do? Go to each library, and add these fields? Not a good solution!! Wouldn't it be nice if all these fields get added to your document library template? This way when you will add a new document library to a site, all the custom fields will already be part of the document library and interestingly, you won't get that dialog box popping up each time a document is added to the library.



Let's create a document library template of our own with the following new fields:

1. Level
2. Workflow
3. Approver

Here are the steps to create a template of our own:

1. Go to following location: C:Program FilesCommon FilesMicrosoft Sharedweb server extensions60TEMPLATE1033STSLISTS

2. Copy "DOCLIB" folder and paste it in the same folder. Rename new folder to "MYDOCLIB"

3. Go to: C:Program FilesCommon FilesMicrosoft Sharedweb server extensions60TEMPLATE1033STSXML. This location contains ONET.XML file.

4. After taking back up of the original file, open ONET.XML and locate the following line:

<ListTemplate Name="doclib" DisplayName="Document Library" Type="101" BaseType="1" 
OnQuickLaunch="TRUE" SecurityBits="11" Description="Create a document library when you have a 
collection of documents or other files that you want to share. Document libraries support features such as 
sub-folders, file versioning, and check-in/check-out." Image="/_layouts/images/itdl.gif" DocumentTemplate="101">
</ListTemplate>
(Note: It should appear on a single line)
 
Copy and paste the following line underneath the above line:
<ListTemplate Name="mydoclib" DisplayName="My Document Library" Type="899" BaseType="1" 
OnQuickLaunch="TRUE" SecurityBits="11" Description="This is a customized Document Library. 
Create a document library when you have a collection of documents or other files that you want to share. 
Document libraries support features such as sub-folders, file versioning, and check-in/check-out." 
Image="/_layouts/images/itdl.gif" DocumentTemplate="101"></ListTemplate>
(Note: It should appear in a single line)
 

5. Open Schema.xml from the following path:

C:Program FilesCommon FilesMicrosoft Sharedweb server extensions60TEMPLATE1033STSLISTSMYDOCLIB

6. Take backup of the original file before making changes. Locate following code in the schema.xml:
<List xmlns:ows="Microsoft SharePoint" Name="Documents" Title="Shared Documents" Direction="0" 
Url="Shared Documents" BaseType="1" >
<MetaData>
<Fields>
 
(Note: It should appear on a single line)

Inside <Fields> tag, you can include your own fields. Add following lines inside <Fields> and </Fields> tags:
<Field Type="Text" Name="Level" ShowInNewForm="FALSE" ShowInFileDlg="FALSE" DisplayName="Level"></Field>
<Field Type="Text" Name="WorkFlow" ShowInNewForm="FALSE" ShowInFileDlg="FALSE" DisplayName="WorkFlow"></Field>
<Field Type="Text" Name="Approver" ShowInNewForm="FALSE" ShowInFileDlg="FALSE" DisplayName="Approver"></Field>

Save schema.xml!

7. Restart IIS.

Now, go to "CREATE" page, you will see two document library templates. Select your newly added template and create a document library. This library will have additional fields by default. You can add as many fields as you like. 
  
-SSA

Sunday, August 6, 2006

SharePoint, Document Library, and SQL Server

I recently published an article on developerfusion.co.uk. Here is the link:

http://www.developerfusion.co.uk/show/5613/

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:

http://office.microsoft.com/en-au/assistance/ha011412871033.aspx  

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:

http://www.microsoft.com/downloads/details.aspx?familyid=4B2C2F1B-D74A-482A-903A-45BB44C5DEC4&displaylang=en

Read more on http://www.developerfusion.co.uk/show/5613/

Regards,

SSA

Thursday, August 3, 2006

Changes in Internet Explorer will affect ActiveX

Microsoft has elected to make major changes in how Internet Explorer launches ActiveX controls. Instead of launching ActiveX controls automatically, the user will have to click on the control to activate it. Microsoft had made the Windows Server 2003 and Windows XP Internet Explorer patch available to the general public as a security update in the April patch cycle (which occurs on the second Tuesday of every month).
More about Patch MS06-013


-SSA

Friday, June 30, 2006

SharePoint Document Puller: Extract any Word document from your SharePoint portal and save it on your hard disk!

This is a small tool developed to extract documents from your SharePoint portal. Documents extracted will be saved to your hard disk. This utility will be of great help to the administrators who use SharePoint as document management system. I have worked with such systems. I have deployed enterprise level document management systems for large organizations and I know they have got hundreds of thousands of documents to store in SharePoint libraries. Searching for specific documents in such a large document management system is a headache, so that is where this tool will come in handy. Users can search for Word documents in SharePoint. Tool will return all word documents from all sites, subsites, libraries, etc. With a single click of a button, user can save the selected document to the hard disk. It's that simple.

I could have made this tool a complicated one with lots of other features but for the sake of simplicity, I have kept it small and simple. This version has two main features:
1. With a single click, you can find all Word documents in your SharePoint deployment.
2. You can save selected document to your hard disk.
Some features that I wanted to implement and might include in the next version:
1. Currently, application retrieves database settings from a text file and hence, it is important for users to modify this text file before being able to use the application. I wanted to include a couple of fields on the form itself so that users would not have to modify the text file. Furthermore, new users may find it difficult to locate the SharePoint database and add it's name to the connection string in the text file.
2. This application searches only Word files in SharePoint whereas it should have the capability to find all other types especially PDF, XLS, PPT, etc. This is not much work and only a couple of lines need to be included in the code. I promise I will do it in next release.
3. Application saves the Word file in the folder where the executable resides. Application should have allowed the user to select a location on the hard disk. This will be included in next release.
Here is what you need to do to run the executable:
1. Edit the db.txt file which is located in the same folder where the EXE resides. This file contains the db connection string. Modify the connection string in this file.
Data Source=sqlserver;Initial Catalog=myPortal1_SITE;User Id=sa;Password=abcd;
"Data source" is your sql server name. "Initial Catalog" contains the name of your portal server site database, for example, if your portal name is "myPortal" then most probably, your database name will be "myPortal1_SITE". Remember, there are three main databases associated with your portal:
a. myPortal1_PROF
b. myPortal1_SERV
c. myPortal1_SITE
We are concerned about the third one only, myPortal1_SITE. You also need to provide User Id and Password (if any) for your database. Modify the connection string and save the db.txt file.
The zip file attached contains only two files: SPDocPuller.exe and db.txt. I could have created an installer but that would have taken a lot of space unnecessarily. I assume you will be running this tool on the SharePoint box. The executable references following files, therefore these should be available on your machine:
1. Microsoft.Office.Core
2. Microsoft.SharePoint.Portal
3. Microsoft.VisualBasic
4. Scripting
Clicking the "Pull Document" button will save the file in the same folder from where you will run the executable file.
I will be looking forward to your comments and suggestions.
Thanks,

-SSA

Friday, June 16, 2006

Manipulating SharePoint list's metadata from inside InfoPath

Yes, this is possible. You can manipulate SharePoint's list metadata from inside InfoPath. You must have InfoPath toolkit installed. See following post for reference:

/ssa/archive/2006/06/02/8029.aspx

You can get/set values in SharePoint list. Recently, I was working on a workflow solution that involved both SharePoint and InfoPath. Till now, all the workflow solutions that I developed used SharePoint as the main tool and workflow was built into SharePoint but this time, the requirement was a bit different. We wanted to build the workflow solution directly in InfoPath form and part of this requirement was to set a property's value in document library directly from InfoPath form. "Approval Status" field in form library can contain one of the following values:

1. Approved
2. Rejected
3. Pending

Depending on your form's requirements, you can set the value of "Approval Status" field directly from InfoPath. Here is the code:

SPWeb mySite = new SPSite("http://yourportal/sites/HR/HRForms/Forms/mod-view.aspx").OpenWeb();
SPFolder myFolder = mySite.GetFolder("HRForms");
SPFileCollection myFiles = myFolder.Files;
try
{
foreach (SPFile fyle in myFiles)
{
fyle.Item.ModerationInformation.Status = Microsoft.SharePoint.SPModerationStatusType.Pending;
fyle.Item.Update();
}
}


Code Explanation:

Open your site using OpenWeb() method. In the code above, first line opens a site called "HR". "HR" site has a folder named "HRForms" and this folder contains all forms. In the for-each loop, we are setting each file's status to "Pending". It is important to call the Update() method in order to apply the changes.

Add a reference to Microsoft.SharePoint (Microsoft.SharePoint.dll) and add following namespaces in the code:

using Microsoft.SharePoint;
using System.Collections;

-SSA

Gates to quit Microsoft

http://www.forbes.com/2006/06/15/gates-retiring-microsoft-cx_gl_0615autofacescan10.html

Any Comments??