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 send email. Show all posts
Showing posts with label send email. Show all posts

Friday, April 21, 2006

SharePoint Document Puller

SharePoint Document Puller

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

Saturday, September 3, 2005

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

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

Monday, January 3, 2005

Sending Email From InfoPath Using Managed Code

It is possible to send an email from InfoPath when a form is submitted. Just add a new data connection and select "Email message" as your data submission method. You can also send email from InfoPath using managed code. You must have InfoPath toolkit installed on your machine in order to write managed code for InfoPath forms.

Ref: /ssa/archive/2006/05/01/6186.aspx

Direct link to download toolkit: http://www.microsoft.com/downloads/details.aspx?familyid=7E9EBC57-E115-4CAC-9986-A712E22879BB&displaylang=en

1. Open your form in design mode and add a button to it.
2. Double click the button and select "Edit Form Code..." from the dialog box that pops up. This will open a Visual Studio editor. Add following code in button's OnClick() event:
[InfoPathEventHandler(MatchPath="CTRL1_1", EventType=InfoPathEventType.OnClick)]
public void CTRL1_1_OnClick(DocActionEvent e)

{
MailMessage MailMsg = new MailMessage();
MailMsg.Body = "This is a test message and currently logged in user is " + System.Environment.UserName;
MailMsg.From = "share.point@yahoo.com";
MailMsg.To = "user@sharepoint.com";
MailMsg.Subject = "InfoPath Test Message";
SmtpMail.SmtpServer = "smtp.yourdomain.com";
SmtpMail.Send(MailMsg);
}

Don't forget to add System.Web.Mail namespace in your code. Add following line in the start of the page:
using System.Web;
using System.Web.Mail;
Hint: Many people complain that they can not add System.Web.Mail to the code. You must add this library in the references before you can use it in your code.
1. Right click "References" in solution explorer and select "Add Reference".
2. Select "System.Web.dll" (.NET Pane) and click OK.

-SSA