A Practical Guide to SharePoint 2013

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

Wednesday, January 18, 2006

Backing Up Sites with Frontpage

You can back up your SharePoint Portal using the Backup utility that comes with the portal but sometimes  you just want to back up a single site, not the whole portal. You can use Frontpage to accomplish this.


1. Open  your site in Frontpage.
2. Go to Tools > Server > Backup Web Site
3. Select "Include websites in archive" in the dialog box that will pop up.
4. Select a location and enter a name for the backup file and click Save. This will save your site as a backup (fwp file). FWP stands for Frontpage Web Package.
Similarly, you can easily restore your backed up site.
1. Go to Tools > Server > Restore Web Site
2. Select the location and file name of your backup file and click OK.
This will restore your site completely but I noticed that your permissions are not restored and you have to restore them manually but that is acceptable. Some times, you have a large site with numerous lists and it is wise to take back up of the site just in case you need it later. Taking backup of a large portal so that you can backup just one site can cost you resources, time and space. This is an easy way to do the job. Another way of taking backups is saving the site as a template and then importing that template in another location. This is a very good way of migrating sites from one server to another. We will discuss that tip next time.
 
-SSA

Tuesday, January 3, 2006

Where can I add my custom built ASPX page in SharePoint easily? Give me an easy solution, I am a beginner!

Category: Administration
Level: Beginner
Custom made ASPX pages or web applications can be deployed in the following location:
C:Program FilesCommon FilesMicrosoft Sharedweb server extensions60TEMPLATELAYOUTS
If you have a single ASPX page that will be called from your SharePoint website or webpart then copy it in the following location:
C:Program FilesCommon FilesMicrosoft Sharedweb server extensions60TEMPLATELAYOUTS1033
Of course, you can also create an excluded path.

Populating InfoPath fields with SQL data (using managed code)

I know it's easy to populate InfoPath form fields with SQL data using data connections but there are certain scenarios where you may want to populate fields with SQL data using custom code. For example, consider a scenario where you form has different sections, and each section is filled with data from a different database. One way is to create multiple data connections in your form. The other way is to write custom code. This is not the only example, there can be different situations where writing your own code could prove useful. Another situation is when you want to validate data entered by a user. Simply, open a connection to your database and check the field's value against data in your database.
1. Create an InfoPath form and add a field and a button.
2. Field name is  "field1" which is the default name for a newly added field. You may want to change it to a name of your liking, for example, First Name, Last Name, Address, etc.
3. Double click the button (default name for the button is Ctrl_1) and select "Edit Form Code..." in the dialog box that opens.
4. Add following code in the click event of the button:
SqlConnection MyConnection = new SqlConnection("server=sqlserver;database=yourdatabase;UID=;PWD=;");
MyConnection.Open();
SqlCommand Cmd = new SqlCommand();
Cmd.Connection = MyConnection;
Cmd.CommandType = CommandType.Text;
Cmd.CommandText = "select * from tblUser";
SqlDataAdapter DA = new SqlDataAdapter(Cmd);
DataSet DS = new DataSet();
DA.Fill(DS);

thisXDocument.DOM.selectSingleNode("/my:myFields/my:field1").text = DS.Tables[0].Rows[1][1].ToString();

if(DS.Tables[0].Rows[1][1].ToString() == "John Doe")
{
thisXDocument.UI.Alert("User name is John Doe.");
}
Code explanation:
Open a connection to the database using a connection string. Connection string contains your sql server, database name and userid and password to access the database. Open the connection before making any transaction. Add your sql query in the command object:
Cmd.CommandText = "select * from tblUser";
Following line will add data from SQL DB to your form field:
thisXDocument.DOM.selectSingleNode("/my:myFields/my:field1").text = DS.Tables[0].Rows[1][1].ToString();
"field1" is your field's name. In the line above, we are populating this field with Row 1, Column 1 of the table.
if(DS.Tables[0].Rows[1][1].ToString() == "John Doe")
{
    thisXDocument.UI.Alert("User name is John Doe.");
}
If DB field is equal to "John Doe" then display a message to the user.
You can also do the opposite, instead of populating a field with DB data, get a value from the form field and find a record against this value in the DB. You just need to pass the form field value in the sql query:
 Cmd.CommandText = "select * from tblUser where username='" + thisXDocument.DOM.selectSingleNode("/my:myFields/my:field1").text + "'";
Don't forget to add following namespaces in your code page:
using System;
using System.Data;
using System.Data.SqlClient;

Add following code to the project class:

public class InfoPathDBProject
{
    private XDocument thisXDocument;
    private Application thisApplication;

    public void _Startup(Application app, XDocument doc)
    {
        thisXDocument = doc;
        thisApplication = app;
    }

    //Application code

}


-SSA

Sunday, January 1, 2006

Test Office 2007 including SharePoint Server online; You just need IE 6

Now, you can test Office 2007 including SharePoint Server and SharePoint Designer online. There is no need to download any software. You just need IE 6 to use online Office. Following applications will be available for online testing:

Microsoft Office Access 2007, Excel 2007, InfoPath 2007, OneNote 2007, Outlook 2007, Outlook 2007 with Business Contact Manager, Outlook Web Access, PowerPoint 2007, Project Professional 2007, Publisher 2007, SharePoint Designer 2007, Visio 2007, Word 2007, SharePoint Services, Project Server 2007 and SharePoint Server 2007.

Here is the link:

http://www.microsoft.com/office/preview/beta/testdrive.mspx?showIntro=n

Click "Test Drive Microsoft Office" button on this page!

-SSA

Saturday, December 3, 2005

How can we create a site in portal server?

How can we create a site in Portal Server?

SPWeb mySite = SPControl.GetContextWeb(Context);
SPWebCollection subSites = mySite.Webs;
string currentTemplate = mySite.WebTemplate;
string siteUrl = TextBox1.Text.ToString(); //you can use hard coded path
here
string siteTitle = TextBox2.Text.ToString(); //you can use hard coded title
for testing purposes
string siteDescription = TextBox3.Text.ToString(); //use hard coded
description for testing
subSites.Add(siteUrl, siteTitle, siteDescription, 1033, currentTemplate,
true, false);

Thursday, November 3, 2005

Deploying .NET application in SharePoint

If you are trying to deploy .NET web application to SharePoint, follow these steps:

1. Create a virtual directory under your portal's website in IIS.
2. Map the virtual directory to the physical file path.
3. Open SharePoint Central Administration page.
4. Click "Windows SharePoint Services" link on the left.
5. Select "Configure virtual server settting" link from "Virtual server
configuration" group.
6. Select your Portal server from the list
7. Click "Define managed path" link under Virtual Server Management group in
Virtual Server setting page.
8. Type name of the virtual directory you created in first step in the Path
section of Add new Path section
9. Select "Exclude path" radio button under the type section
10. Click "Ok"
11. Navigate to http://your_portal/your_application/default_page.aspx

Monday, October 10, 2005

SQL Server: Detach and Attach a DB

Target Audience: Beginners
Keywords: SQL Server, Attaching Databases
This post is not related to SharePoint directly but yes indirectly it is still related to SharePoint. I do lots of applications for SharePoint. I create custom built solutions in .NET for SharePoint. I don't like the back up utility of SQL Server. It is not reliable as it misses several stored procedures when restoring. Although it does not happen always but no body likes to take chances so i usually back up my database by detaching the db and saving the .MDF file to the back up folder. I also use the same mechanism for replicating the DB. Some times when you get stuck when attaching the detached DB. For example, consider this scenario. I want to replicate a DB. I detach the original DB and make a copy of it and rename it. I attach the original DB without any problem but when i try to attach the renamed DB copy, I get an error. This is not a technical solution to a problem as problem itself does not exist :) This is a very simple tip but many users will find it very useful. Believe me. When you are in a hurry to do a replication and could not find the solution, this tip will really come in very handy. Anyway, here are the steps involved:
1. Right click Databases. All Tasks > Attach Database.
2. Browse to find the renamed DB file (the MDF file).
3. Under "Current File(s) Location", double click the file name and change it to the new name. The box shows you the original MDF file name even though you have renamed it. Rename it and DO NOT HIT THE ENTER BUTTON. Instead, use your mouse and click somewhere in the second row. When you hit the enter button, SQL Server does not accept your change and reverse the file name back to the original file name but when you move your focus away from first row to second row by simply clicking the mouse, this problem does not occur.
4. "Attach As" also will still be showing the original file name. Type in the new name that you want to give to your database.
5. Specify the database owner and you are done.
Very simple! What's the big deal in it? Yes, what's the big deal in it? If you are a senior DBA reading this post and laughing and thinking why i am posting such a simple thing then let me tell you you were not the intended audience for this post. This happens with me very frequently. People criticize me for posting simple solutions but let me tell you that my goal is to write for every one, not just for the senior people. Most of the emails that i daily receive are from the young people are still learning the tricks of the trade. We can not ignore them or move away instead of helping them. Well, it gives me pleasure when a senior person appreciates my work but it equally pleases me when a beginner takes advantage of my simple tips and praises my work and thank me for writing it. So, getting back to the tip, here is one final note. If you get an error while attaching the DB without any apparent reason, see if your SQL query analyzer is open and you are accessing the DB in it. Some times, it happens that you are working in Query Analyzer, you leave the session open and detach the DB, for any purpose, be it taking backup or replication, when you try to re-attach the DB, you get an error telling you that attaching failed!! You don't see any reason why your attaching failed. This happens because of the open sessions in your Query Analyzer. Close the session by closing the Analyzer and try attaching the DB again.
Visit the following link to see how to attach a DB using T-SQL:


-SSA