A Practical Guide to SharePoint 2013

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

Tuesday, February 28, 2006

How to connect a web part to the aspx page?

How to connect a web part to the aspx page?

Scenario: I have created a workflow application for Document and Form Libraries. I have also created an "Administration" application for this workflow application. Admin application consists of a web part. I want to include a button in the navigation bar of the document/form library and clicking that button will take the user to an aspx page which will contain my "admin" web part.
1. Here is the screen shot of the document library:
Note the "Administration" button in the menu bar (encircled in red). This is the new button i just added. This page is linked to the aspx page that contains my web part. Here are the steps:
1. First, decide where you want to include this new link. In your document library? In your form library? Do you want to create a new document library or do you want to modify default document library? Modifying the default document library is not recommended. Keep the default document library intact and create a new document library template instead. As an example, i am adding this button to my form library. Edit the schema.xml file in your form library template. The path is:
C:Program FilesCommon FilesMicrosoft Sharedweb server extensions60TEMPLATE1033STSLISTSXMLFORM
Edit the schema.xml file in editor. Locate following text in the file:

<Default>
<Switch><Expr><GetVar Name="GridSwitch"/></Expr>
<Case Value="Unavailable">
</Case>
<Default>
<HTML><![CDATA[
<TD class="ms-toolbar"> <table cellpadding=1 cellspacing=0 border=0> <tr> <td class="ms-toolbar" nowrap> <a tabindex=2 ID=diidEditInGridButton class="ms-toolbar" title=]]></HTML><HTML>"Edit in Datasheet"</HTML><HTML><![CDATA[ ACCESSKEY=G href="BLOCKED SCRIPTEditInGrid(]]></HTML><GetVar Name="WPQ"/><HTML><![CDATA[varPageUrl,']]></HTML><GetVar Name="View" URLEncode="TRUE"/><HTML><![CDATA[');" target=_self> <img src="/_layouts/images/editgrid.gif" ID="tbbuttonstart1" alt=]]></HTML><HTML>"Edit in Datasheet"</HTML><HTML><![CDATA[ border=0 width=16 height=16></a></td> <td nowrap> <a tabindex=2 ID=diidEditInGridButton class="ms-toolbar" ACCESSKEY=G href="BLOCKED SCRIPTEditInGrid(]]></HTML><GetVar Name="WPQ"/><HTML><![CDATA[varPageUrl,']]></HTML><GetVar Name="View" URLEncode="TRUE"/><HTML><![CDATA[');" target=_self>
]]></HTML><HTML>Edit in Datasheet</HTML><HTML><![CDATA[
</a> </td> </tr> </table> </TD>
At the end of the above code, copy the following additional code. This will add a new button:
<TD class=ms-separator>|</TD>
<TD class="ms-toolbar"> <table cellpadding=1 cellspacing=0 border=0> <tr> <td class="ms-toolbar" nowrap> <a tabindex=2 ID=diidEditInGridButton class="ms-toolbar" title=]]></HTML><HTML>"Edit in Datasheet"</HTML><HTML><![CDATA[ ACCESSKEY=G href="BLOCKED SCRIPTAdministration(]]></HTML><GetVar Name="WPQ"/><HTML><![CDATA[varPageUrl,']]></HTML><GetVar Name="View" URLEncode="TRUE"/><HTML><![CDATA[');" target=_self> <img src="/wpresources/EPWebParts/1.0.0.0__32bb15c33a2f8eca/images/admin.jpg" ID="tbbuttonstart1" alt=]]></HTML><HTML>"Workflow Administration"</HTML><HTML><![CDATA[ border=0 width=16 height=16></a></td> <td nowrap> <a tabindex=2 ID=diidEditInGridButton class="ms-toolbar" ACCESSKEY=G href="BLOCKED SCRIPTAdministration(]]></HTML><GetVar Name="WPQ"/><HTML><![CDATA[varPageUrl,']]></HTML><GetVar Name="View" URLEncode="TRUE"/><HTML><![CDATA[');" target=_self>
]]></HTML><HTML>Administration</HTML><HTML><![CDATA[
</a> </td> </tr> </table> </TD>

Note the bold text in the above code. Administration() is the function that will be called on the click of the new link. Where this function will be added, i will tell you later. You also need to provide proper path to the link's image. "wpresources" is a good location to add store your image along with your web part.
Location of the "wpresources" folder in your inetpub. On my machine the path is:
Because i have installed SharePoint on a different port other than the default port, therefore, i have a different path. Whatever is your default site path, add the "wpresources" folder. This folder will contain another folder that will contain your web part files. "js" folder contains the javascript file that contains the "Administration()" function. Another good location to include this function which many people find easier to find is "ows.js" in the following default path:
C:Program FilesCommon FilesMicrosoft Sharedweb server extensions60TEMPLATELAYOUTS1033
"ows.js" is the default script file that contains all the SharePoint functions. Modifying this file is not a good practice. Either take back up of the original file before modifying it or there are other methods, for example, creating a new script file that will overwrite your default script file. See SDK for more information. Right now, i will be modifying the default js file. Edit the ows.js in your favorite editor and add the following function anywhere in the file:
function Administration(using, viewguid)
{
    document.location = 'AppForm.aspx';
}
Now, you also need to include the AppForm.aspx that you are using in your function. Where will this page be added? The aspx page will be added in your form library's folder. For example, if you are adding new link in your Form library, then add AppForm.aspx in the following folder:
C:Program FilesCommon FilesMicrosoft Sharedweb server extensions60TEMPLATE1033STSLISTSXMLFORM
This ASPX page contains your webpart:
<%@ Register Tagprefix="EPWebParts" Namespace="SharePoint.AdminWebParts" Assembly="AdminWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=65fb13d34a5f5gsa"%> 
 

Friday, February 24, 2006

Creating Reports with Access

Long time ago, some one asked me whether we could export data from SharePoint to Access and my answer was "Yes, we can. Export data to spreadsheet using the Export to spreadsheet link and then manually import data from the Excel sheet into the Access database.". That was long time ago, I didn't know at that time that it was possible to export data to Access directly from with in SharePoint. Not only that, you can create reports easily from with in SharePoint. For example, you have a document library with a long list of documents, you want to create and present a report containing this list of documents to your manager. You can create a beautifully formatted report using Access. Here is how you do it:

1. In document library, click "Edit in Datasheet".
2. Click Task Pane to open it. It will show you office links.
3. Click "Report with Access". You can export data to an existing database or if you don't have an already created database, you can create a new one. When you  click "Report with Access".  SharePoint asks you whether you want to export to an existing database or create a new database. Select your option and click OK. SharePoint does the remaining work. It will create a table in Access, add data to that table and then create a clean simple report for you. Now if you want to format the report, click the Design button and add the header and footer of your choice. Add colors, borders or what ever you like in the report template. Save it and you are done.
This tip shows you how you can create a report containing data from a document library. You can use same functionality to create reports for other lists. I think this is a very easy way of creating cool reports.

-SSA

Tuesday, February 14, 2006

Working With Excel

Many people know that it is easy to save lists in SharePoint as Excel sheets. For example, if you are in a document library, select "Export to spreadsheet" from the Actions menu to export data to Excel. There are other things that you can do with Excel, for example, you can create charts with Excel, you can print content, etc. Another interesting feature is that you can edit your SharePoint lists in Excel.
1. If you have a document library, select "All Documents" view and click "Edit in Datasheet".
2. Click "Task Pane" to open the task pane. You will notice there are several features that you can take advantage of. Because we are discussing Excel at the moment, so let's stick with it.
3. In the Task Pane, select "Export and Link to Excel". "Opening Query" dialog box will pop up. Click "Open" to open the Excel sheet.
4. Another pop up dialog box "Import Data" will open up. By default, "New workbook" is selected. Click OK to open a new workbook.
5. Now, you can edit any of the row in the list. There are some columns like Modified By, Created By, etc that you can not edit but other fields especially custom fields can be edited and once you are done with editing, select Data > List > Synchronize List to synchronize the list. Your data will synchronize with SharePoint. Easy? Isn't it?

-SSA

Saturday, February 4, 2006

How can we retrieve an older version of a document using .NET?

How can we retrieve an older version of a document using .NET?

spFile = EventWeb.GetFile( _FileName );
if (spFile.Versions.Count > 1)
{
 //restore previous version
 spFile.Versions.Restore(spFile.Versions.Count - 1);
}
Similarly, you can delete the document version:
spFile.Versions.Delete(spFile.Versions.Count - 1);

Friday, February 3, 2006

Publish Your "MS Dynamics SL/Word Documents" to a SharePoint Site

I was reading this article on Microsoft which shows us how to publish Dynamic SL Documents to a SharePoint site.
You can follow the same steps to publish your word documents to a SharePoint site. There are other means to do this as well but just for the sake of experimenting, i thought it would be nice to see how things work.
> When you  install MS Office 2003, you get a new printer - the Microsoft Office Document Image Writer printer.
> When you install Adobe, you get a new printer - Adobe Distiller.
Why I mention Adobe is because you can publish your documents as PDFs using Adobe Distiller.

1. Map a drive to your SharePoint document library.
2. Open word document on your local drive and click Ctrl-P to open printer options. Change your printer to Microsoft Office Document Image Writer printer.
3. Click OK to print, the File Save As dialog box will open. Select your mapped drive, give a name to your file and click OK.
This won't save your file as a Word document. It will save it in MDI format and clicking this file in SharePoint won't open it directly but you will be asked whether you want to open or save it.  It will be opened in Microsoft Office Document Imaging.
If you want to convert your document to PDF, select Adobe Distiller as your printer. Your documents will be saved as PDFs.
Another thing that you may be interested in is you can decide what to print. You can print the whole document or you can just print the document properties. There is a drop down "Print What" in Print Options dialog box. Select "Document properties" to print document properties only.

-SSA

Error: SharePoint backup tool must execute on a web client.

Error: SharePoint backup tool must execute on a web client.

I am posting this hoping that someone may find it useful. It is a common practice to migrate SharePoint deployment from one machine to another. Many people use Backup and Restore utility that comes with SPS 2003. Recently, someone asked me a question that when he tried to run the backup tool to restore a site, he got following error message:
"SharePoint backup tool must execute on a web client."
The user was quite confused.

Perform these actions to solve the problem:
1. Open SharePoint Central Administration page.
2. Click "Configure server topology".
3. Click "Change Components" button
4. Check "Web" (Component Assignment) if not already checked.
5. Click OK.
6. If you are trying to restore to a new site, create that site first in IIS.
Try running the backup tool again, it should work fine now.