A Practical Guide to SharePoint 2013

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

Friday, September 23, 2005

Submitting InfoPath form to two locations (DB and SharePoint)

Yes, it is possible to submit InfoPath form to two locations. Create two data connections. One will submit data to database and the other will link to your SharePoint library. Create a rule that will use both data connections when a user hits the submit button.

1. Select Tools > Submitting Forms
2. Click Rules
3. Add a Rule
4. Add two actions: Submit using database connection and Submit using SharePoint connection.
5. Save the settings
6. Publish your form in SharePoint.

Now when user hits the "Submit" button, data from InfoPath form will go to the DB and form will be saved in SharePoint as well. 

-SSA

Saturday, September 3, 2005

How to use UserProfileManager in .NET code?

TopologyManager topology = new TopologyManager();

  PortalSite portal = topology.PortalSites[new Uri("http://test-server")];

  PortalContext context = PortalApplication.GetContext(portal);

  UserProfileManager profileManager = new UserProfileManager(context);

Taking Backup of IIS 6.0

This may prove to be useful especially if you want to take back up of SharePoint virtual servers, application pools, etc.

To take backup of IIS 6.0, follow these steps:

1. Open IIS
2. Select server (Right Click) > All Tasks > Backup/Restore Configurations
3. Click "Create Backup"
4. Name your backup and click OK. You can encrypt your backup using a password.
"Create Backup" and "Restore" buttons are placed side by side.
To restore:
1. Open IIS
2. Select server (Right Click) > All Tasks > Backup/Restore Configurations
3. Click "Restore" to restore the metabase.

-SSA

Sending email in InfoPath using third party component

You can send email in InfoPath using third party components. You must use InfoPath Toolkit. Toolkit is required to write managed code in InfoPath. To see how you can send email using System.Web.Mail namespace, read following post:

Sending Email From InfoPath Using Managed Code

I used ASPEmail component in my code, this component can be downloaded from the following link:

www.aspemail.com

After downloading the component, install it on your machine. Create an InfoPath form and add a button to it. Double click the button and select "Edit Form Code..." from the dialog box. This will open code editor (in Visual Studio). Add component in references. Right click "References" in solution explorer and add a reference to ASPEmail component (ASPEmailLib.dll).
Include namespace in your code: using ASPEMAILLIB;
Add following code click event of the button:

[InfoPathEventHandler(MatchPath="CTRL1_1", EventType=InfoPathEventType.OnClick)]
public void CTRL1_1_OnClick(DocActionEvent e)
{
ASPEMAILLib.IMailSender objMail;
objMail = new ASPEMAILLib.MailSender();
objMail.Host = "smtp.yourdomain.com";
objMail.From = "share.point@yourdomain.com";
objMail.AddAddress("user@sharepoint.com" , "John Doe");
objMail.Body = "This a test mail and currently logged in user is " + System.Environment.UserName;
objMail.Send("share.point@yourdomain.com");
}

You can send attachments as well. Add following line before the "send" statement:
objMail.AddAttachment(your file path);
To add CC address, use the following line:
objMail.AddCC("email address","user name");
To add BCC address, use the following line:
objMail.AddBcc("email address","user name");
To send HTML mail, set isHTML property to true:
objMail.IsHTML = true;
To send mail to a newsgroup:
objMail.SendToNewsgroup(string newsgroup);


-SSA

Showing "Previous" link in document libraries

How can we show "Previous" link in our document libraries? I have been asked this question many times and i have answered it on newsgroup as well. Suppose, you have limited the number of records to be displayed on a single page of a view to 10 and total number of records exceeds 10. What will happen? Paging! Yes, a "Next" link will be added at the bottom of the view. You can move forward using the "Next" link but how would you go back? There is no "Previous" link. Users have to hit the browser's back button in order to go back and this annoys many site administrators. Well, here is one solution to show the "Previous" link along side "Next" link:


1. Open your list in Frontpage.
2. Open the page for the view for which you want to add the previous link, for example, open AllItems.aspx for "All Tasks" view  or open duetoday.aspx
for "Due Today" view.
3.Right click list view to open the context menu. Select "Convert to XSLT Data View" from the context menu.
4. Save your list.

Preview modified view in SharePoint, you will see both "Next" and "Previous" links at the bottom of the list.

-SSA

Sending email after submitting InfoPath form (without coding)

Q: I use InfoPath form to submit data to a database. My form is published in SharePoint. How can I send an email either to myself or to some one else right after submitting the form?


Why don't you use Infopath's built in functionality? You have created a data connection to submit data to database. Create another connection that will send an email to your account. In Tools > Submitting Forms > Rules, Add a new rule. Add action in this rule. Select "Submit using a data connection" in the actions drop down and select email connection in the "Data Connection" drop down.


--SSA

How can I hide "Issues" List Template from users?

Q: I want to hide "Issues" List Template from users. Is it possible?

When you click "Create" link in the navigation bar at the top you are shown templates for different lists including document and form libraries, contact, issues, tasks, events lists. Yes, you can hide a template by modifying the ONET.XML file. To hide the "Issues" list, follow these steps:

1. Go to this location:
C:Program FilesCommon FilesMicrosoft Sharedweb server extensions60TEMPLATE1033STSXML
2. Open ONET.xml file for editing and please back up the original file before making any changes.
3. You will find list definitions for different lists inside tag. Simply comment out the list definition that you don't want to appear in the CREATE page. Use tags to comment out the line. For example, the following line will hide the "Issues" list template on the CREATE page:
-->
4. Save the file and Restart IIS.
5. Remove tags to uncomment the line and make the list visible again.

Caution: If you remove a list template from the ONET file, your existing lists based on that template will also cease to work.

-SSA

How can I send email to the user who modifies the document?

spListItem["Modified By"] property gives you the name of the person who last modified the document.
Have a look at the following code. You can get file's URL in EventFileURL if you are using EventHandlerToolkit.

spFile = EventWeb.GetFile( EventFileUrl );
if (spFile.Exists)
{
spListItem = spFile.Item;
}
string strModifiedBy = spListItem["Modified By"].ToString();

and if you want to send an email, here is how you can do it. You can send email in OnDelete(), OnInsert(), OnUpdate(), etc

private void OnDelete()
{
    //Insert code here: capture the name of the person who modified the document
    //Send email
MailMessage msg;
  
SmtpMail.SmtpServer = "smtp.yourserver.com";
msg = new MailMessage();
msg.BodyFormat = MailFormat.Html;
msg.From =  currentWeb.Author.Email; //you can use hard code the sender here
msg.Subject = "File Deleted";
msg.Body = "File has been deleted";
msg.To = currentWeb.Users[strModifiedBy].Email;
SmtpMail.Send(msg);
    
}
-SSA

Friday, September 2, 2005

How to get a list of sites in SharePoint using .NET code?

Here is how you can get a list of sites. The following function will retrieve a list of sites from your main portal address. All site names will be written to a text file.
Function GetFolders(ByVal rootsite As String)
//rootsite contains your main portal address, for example,
http://myportal
Dim strSites As String = ""
Dim mysite As SPSite
mysite = New SPSite(rootsite)

Dim subSites As SPWebCollection = mysite.AllWebs

Dim i As Integer

For i = 0 To subSites.Count - 1

Dim lists As SPListCollection = subSites(i).Lists

Dim j As Integer

Dim siteurl As String

For j = 0 To lists.Count - 1

strSites = strSites & SPEncode.HtmlEncode(subSites(i).Title) & ": " & SPEncode.HtmlEncode(lists(j).Title) & vbCrLf

//Insert Check Rights code here!!!

Next

Next

Dim sw As StreamWriter = File.AppendText("sites.txt")

sw.WriteLine("[" & Date.Now & "]")

sw.WriteLine(strSites)

sw.Flush()

sw.Close()

MsgBox("File created successfully. See 'sites.txt'!")

End Function

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