Tuesday, 6 March 2012

Hello to Myself

Hello To Myself Lyrics (Dream High 2 OST) – YeEun (Wonder Girls)

Hello yeo-gin icheonshibinyeon iworaju chu-un gyeou-riya
Where are you eolmana kakka-i wah i-nni
keutorok wonhadeon kkume

yeo-gi nan ajing neomeojigo tto ul-ko
dachigo jichyeoseo i-reoseol himjocha eop-seo
keuchiman neon nal bogo utket-ji

Hello to myself hello to myself ul-ji malla-go nal wiirohaeju-llae
Hello to myself hello to myself hal su it-da-go neo marhaeju-llae
Hello hello ul-jima Hello hello i-reona

How are you eotteon-i kkumeurirundaneun geon cheongmal kkojibeodo apeuji
anh-ni
eocheomyeon ijen ne-gen pyeongbeomhan il-sangira ttaeron jikyeomni
hokshi neodo wehrob-go jichimyeon yeo-gi kkumkkudeon nal giyeo-khaeju-llae

Hello to myself hello to myself yeo-gi nal saenggakhamyeo useo ju-llae
Hello to myself hello to myself gaseum beokcha-ge haengbo-khae ju-llae
Hello hello useobwah Hello hello keureohke

Hello to myself hello to myself
yeo-gi nal saenggakhamyeo useo ju-llae
Hello to myself hello to myself
kkumkkudeon nari-jji maraju-llae

Translation:
Hello, this is February 2012, a very cold winter
Where are you - how close are you
To the dream that I wanted so bad?

Here, I'm still falling and crying again
I'm hurt and tired and have no strength to get up
But you would probably see me and smile

Hello to myself hello to myself
Will you comfort me, saying don't cry?
Hello to myself hello to myself
Will you tell me that I can do it?
Hello hello - don't cry - Hello hello - get up

How are you - how is it to fulfill your dream?
Doesn't it hurt when you pinch yourself?
Or is it sometimes boring because it's become a normal routine for you?
If you ever get lonely and tired, will you remember me, who used to dream here?

Hello to myself hello to myself
Will you think of me here and smile?
Hello to myself hello to myself
Will you be happy to the point where your heart overflows?
Hello hello, smile - Hello hello, just like that

Hello to myself hello to myself
Will you think of me here and smile?
Hello to myself hello to myself
Will you not forget me, who used to dream?

SPFile Class Vs SPList

From : http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfile.aspx

SPFile Class

SharePoint 2010
This topic has not yet been rated Rate this topic
Represents a file in a SharePoint Web site that can be a Web Parts page, an item in a document library, or a file in a folder.
System.Object
  Microsoft.SharePoint.SPFile
Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
[SubsetCallableTypeAttribute]
public class SPFile
Use the GetFile or GetFileAsString method of the SPWeb class to return a single file object. Otherwise, use the Files property of either the SPWeb or SPFolder class to return an SPFileCollection object that represents the collection of files for a site or folder. Use an indexer to return a single file from the collection. For example, if the collection is assigned to a variable named collFiles, use collFiles[index] in C#, or collFiles(index) in Visual Basic, where index is the index number of the file in the collection, the file name including extension, or a Web site relative, site collection relative, or absolute URL.
This example adds a file from the document library of one site to the Shared Documents document library of another site and its subsites.
For an example that shows how to upload a local file to a folder on a SharePoint site programmatically, see How to: Upload a File to a SharePoint Site from a Local Folder.
SPSite oSiteCollection = SPContext.Current.Site;
SPWeb oWebsiteSrc = oSiteCollection.AllWebs["Source_Site_Name"];
SPWebCollection collWebsites = 
    oSiteCollection.AllWebs["Destination_Site_Name"].Webs;

SPFile oFile = oWebsiteSrc.GetFile("Source_Folder_Name/Source_File");
string strFilename = oFile.Name;
byte[] binFile = oFile.OpenBinary();

foreach (SPWeb oWebsite in collWebsites)
{
    if (oWebsite.GetFolder("Shared Documents").Exists)
    {
        SPFolder oFolder = oWebsite.GetFolder("Shared Documents");
        oFolder.Files.Add(strFilename, binFile, true);
    }
    oWebsite.Dispose(); 
}
oWebsiteSrc.Dispose();
NoteNote
Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Saturday, 3 March 2012

New week, NEW JOB

Hi!
I've been travelling for the time eing. Penang-johor-penang-shah alam-penang-vietnam...fuhhhh what a tough month. So, back to the office work keep on increasing just like an exp graph. :( sigh
 now, i need to solve the linkage between FMEA-Control whichj i thought had long resolve. Hahaha..being management is such a GREAT thing when they can say a DONE work is still NOT DONE and NOT SATISFYING. :( sigh

Ok, back to what i want to complete this week :
first i need to change the FMEA + Control Plan + SPC to become a two way data entry.This will be done by changing the dropdown to a combobox, and adding this codes :

public void school_Changed(object sender, XmlEventArgs e)
{
  using (SPSite FormSite = new SPSite(ServerInfo.SharePointSiteUrl.ToString()))
  {
    using (SPWeb FormWeb = FormSite.OpenWeb())
    {
      //Get the list and query for the item - "Schools" is the name of the list I am retrieving
      SPList LookupList = FormWeb.Lists["Schools"];
      SPQuery MyQuery = new SPQuery();
      //"Title" is the field where I keep the school name
      ///my:myFields/my:school is the xpath to the school field
      MyQuery.Query = "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + GetDomValue("/my:myFields/my:school") + "</Value></Eq></Where>";
      SPListItemCollection ReturnedItems = LookupList.GetItems(MyQuery);
      //Add the item to the lookup list if no items were returned in the query
      if (ReturnedItems.Count == 0)
      {
        SPListItem NewItem = LookupList.Items.Add();
        ///my:myFields/my:school is the xpath to the school field
        NewItem["Title"] = GetDomValue("/my:myFields/my:school");

Then Walla!

Next i want to change the inner e form of FMEA to a more user friendly thing. That one need some brainstorming. Last time i just use email alert, this time...errrr~ dont know yet.

Last thing is to revamp the control plan form. hmmmm :( sigh.
Its STILL A BIG FAT BLURR~

Wednesday, 15 February 2012

Search title "SharePoint 2010 Document Library Upload Issues "

 Hi!

I oftenly came accross client that ask wether multiple documents upload are available in sharepoint.  i can, they wanted to just upload the whole folder from their current document location straight into the SP site. huhuhu. humans are really into things that would make their life easy. Em so then, only now i have the time to look it up and i came across this.

From :http://www.anmolrehan-sharepointconsultant.com/2012/01/sharepoint-2010-document-library-upload.html

 

Sunday, January 22, 2012

SharePoint 2010 Document Library Upload Issues

Issue 1:
Can't upload more than 100 documents at a one time in SharePoint 2010 Library.


Solution:
Open Library in Explorer View. This way you can upload as many as documents as you like.

Issue 2:
Can't upload documents more than some MB's size

Solution: 

  • Open Central Administration
  • Go to Application Management > Manage Web applications
  • Select Web application and click "General Settings"
  • Scroll down to modal window and change "Maximum Upload Size". You can set this to maximum of 2GB.
  • You may encounter "Security Validation error if upload is taking time more than 30 mins. To resolve this issue. Scroll up and change "Security validation expires"

Issue 3:
Upload Multiple Documents link is greyed out.

Solution 1
This will be greyed out if you have opened the site in Mozilla Firefox. Open site in Internet Explorer and it will be fine.

Solution 2
This is actually client integration component  and can be available if office 2010 client installed. First time you navigate to library you will be asked for an ActiveX Control. You need to install that and everything will work fine.

Tuesday, 14 February 2012

Me and workflow - "Start a new workflow after this Workflow end"

Hi!

Here's the thing.... i just realize that SPD2010 don't have the workflow called "Start another WF"..before, when using SPD2007, i knw how to custom made this WF.  Now, i'm using SPD2010, more of the functions are not easy to customized. It's easy for beginners but such a prison for people who wants it to be more flexible. :((

So, i thought of finding some ways to create these custom WF. All of the things that i find in the net regarding this, i'll will compile it here. So, this entry will be a LONG~~ entry. :D ]

Hope i have time to try it one by one..hehehehe >_< 

1)From : http://www.anmolrehan-sharepointconsultant.com/2011/09/workflow-activity-to-trigger-another.html

SharePoint 2010: Workflow Activity to trigger another Workflow

While creating a workflow in SharePoint Designer, You may find a situation in which you may require to create a Step to trigger another workflow on same list. By default its not possible in Sharepoint Designer. So to achieve this we can create a custom workflow activity.

Steps to acheive this
  • Create Empty SharePoint Project.
  • Add Sharepoint Mapped Folder
    "{SharePointRoot}\Template\1033\Workflow"
  • Create new file "SPDStartWorkflow.actions" in mapped folder. And paste below code in this
    <?xml version="1.0" encoding="utf-8" ?>
    <WorkflowInfo>
      <Actions Sequential="then" Parallel="and">
        <Action Name="Start Another Workflow"
         ClassName="WorkflowStarter.StartAnotherWorkflow"
         Assembly="WorkflowStarter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3b0e31fdf8deb757"
         AppliesTo="all"
         Category="Custom Actions">
          <RuleDesigner Sentence="Start another workflow on %2, named %1">
            <FieldBind Field="WorkflowIdentifier" Text="Call Self" Id="1" DesignerType="TextArea" />
            <FieldBind Field="ListId,ListItem" Text="this item" Id="2" DesignerType="ChooseListItem" />
          </RuleDesigner>
          <Parameters>
            <Parameter Name="__Context" Type="Microsoft.SharePoint.WorkflowActions.WorkflowContext" Direction="In" />
            <Parameter Name="WorkflowIdentifier" Type="System.String, mscorlib" Direction="Optional" />
            <Parameter Name="ListId" Type="System.String, mscorlib" Direction="In" />
            <Parameter Name="ListItem" Type="System.Int32, mscorlib" Direction="In" />
          </Parameters>
        </Action>
      </Actions>
    </WorkflowInfo>

  •  Add new class "StartAnotherWorkflow" and inherit it from "Activity". Add below code in file.
        public static DependencyProperty __ContextProperty = DependencyProperty.Register("__Context",
                                                                                       typeof(WorkflowContext),
                                                                                       typeof(StartAnotherWorkflow));


        public static DependencyProperty ListIdProperty = DependencyProperty.Register("ListId", typeof(string),
                                                                                      typeof(StartAnotherWorkflow));

       
        public static DependencyProperty ListItemProperty = DependencyProperty.Register("ListItem", typeof(int),
                                                                                        typeof(StartAnotherWorkflow));

       
       public static DependencyProperty WorkflowIdentifierProperty = DependencyProperty.Register("WorkflowIdentifier",
                                                                                                  typeof(string),
                                                                                                  typeof(
                                                                                                      StartAnotherWorkflow
                                                                                                      ), new PropertyMetadata(""));


        [ValidationOption(ValidationOption.Required)]
        [Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public WorkflowContext __Context
        {
            get { return ((WorkflowContext)(base.GetValue(__ContextProperty))); }
            set { base.SetValue(__ContextProperty, value); }
        }

       
        [Description("ID of the list we are working with")]
        [ValidationOption(ValidationOption.Required)]
        [Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public string ListId
        {
            get { return ((string)(base.GetValue(ListIdProperty))); }
            set { base.SetValue(ListIdProperty, value); }
        }

       
        [Description("ID of the list item we are working with")]
        [ValidationOption(ValidationOption.Required)]
        [Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public int ListItem
        {
            get { return ((int)(base.GetValue(ListItemProperty))); }
            set { base.SetValue(ListItemProperty, value); }
        }

       
        [Description("Workflow name or template base id")]
        [ValidationOption(ValidationOption.None)]
        [Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public string WorkflowIdentifier
        {
            get { return ((string)(base.GetValue(WorkflowIdentifierProperty))); }
            set { base.SetValue(WorkflowIdentifierProperty, value); }
        }

       
         protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            try
            {
                //need to run under SHAREPOINT\system account because workflow owner might not have start workflow permissions on the target list
                SPSecurity.RunWithElevatedPrivileges(delegate
                {
                    using (SPSite site = new SPSite(__Context.Site.ID))
                    {
                        using (SPWeb web = site.AllWebs[__Context.Web.ID])
                        {
                            SPList list = web.Lists[new Guid(ListId)];

                           
                            SPListItem listItem =
                                list.Items.GetItemById(ListItem);

                           
                             //resolve any lookup parameters
                            string wkId =
                                Common.ProcessStringField(executionContext,
                                                          WorkflowIdentifier);

                           
                            //find workflow association by name
                            SPWorkflowAssociation myWorkflowAssoc =
                                list.WorkflowAssociations.GetAssociationByName(
                                    wkId, Thread.CurrentThread.CurrentCulture);
                           
                            if (myWorkflowAssoc != null)
                            {
                                //start the workflow
                                site.WorkflowManager.StartWorkflow(listItem,
                                                                   myWorkflowAssoc,
                                                                   myWorkflowAssoc.AssociationData);
                            }
                        }
                    }
                });
            }
            catch (Exception e)
            {
              
            }

            return ActivityExecutionStatus.Closed;
        }
 2) From : http://msmvps.com/blogs/sundar_narasiman/archive/2010/12/26/develop-custom-workflow-activity-for-sharepoint-2010-workflow.aspx
There is some error in the codes though.

Develop Custom Workflow Activity for SharePoint 2010 Workflow

In this article, I’d be discussing the steps to create a custom workflow activity for SharePoint 2010. The need for custom workflow activity arises, when the out-of-box workflow activities do not suffice our requirement. The functionality of developing a custom activity for SharePoint 2010 Workflow is not a new feature in SharePoint 2010. This was available in SharePoint 2007, which is now continued to SharePoint 2010. Once the custom workflow activity is created, it can be made available for use inside SharePoint Designer 2010.

File ---> New Project
Select -----> Visual C# ---> SharePoint | 2010 ----> Empty Project
custom activity 1
custom activity2


Click Finish
File ---> Add –> New Project
Select the Visual C# | Workflow | Workflow Activity Library and set the project name as ‘CreateActivityDemo’.
custom activity3[5]
Right click ‘CreateActivityDemo’ project and add a reference to Microsoft.SharePoint.dll and Microsoft.SharePoint.Workflow.Actions.dll
Add a new workflow activity called ‘CreateSurveyLibrary.cs’
Switch to view code of ‘CreateSurveyLibrary.cs’
Import the following namespaces
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;
using Microsoft.SharePoint.Workflow Actions;
 
Add a dependency property property by name ‘SiteUrlProperty’
public static DependencyProperty SiteUrlProperty = DependencyProperty.Register("SiteUrl", 

typeof(string), typeof(CreateSurveyList), new PropertyMetadata(""));
[DescriptionAttribute("Url of site where survey is to be created")]
[BrowsableAttribute(true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
[ValidationOption(ValidationOption.Optional)]
public string SiteUrl
{
get
{
return ((string)(base.GetValue(CreateSurveyList.SiteUrlProperty)));
}
set
{
base.SetValue(CreateSurveyList.SiteUrlProperty, value);
}
}
The SiteUrlProperty is used to capture the url of the site, in which the survey list needs to be created. The convention for creating the dependency property is to have the keyword ‘Property’ appended (at the end) to the name of the actual property. In this case, the name of the regular C# property is SiteUrl, the dependency property is created with convention of ‘SiteUrlProperty’. If this naming convention is not followed, we’ll get a compilation error.

Add another dependency property called ‘SurveyListNameProperty’. This is used to assign the name for Survey List during the list creation.

public static DependencyProperty SurveyListNameProperty = DependencyProperty.Register("SurveyListName", 

typeof(string), typeof(CreateSurveyList), new PropertyMetadata(""));
[DescriptionAttribute("Name for survey list")]
[BrowsableAttribute(true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
[ValidationOption(ValidationOption.Optional)]
public string SurveyListName
{
get
{
return ((string)(base.GetValue(CreateSurveyList.SurveyListNameProperty)));
}
set
{
base.SetValue(CreateSurveyList.SurveyListNameProperty, value);
}
}
Again, follow the same naming convention for creating this dependency property ‘SurveyListName’, discussed above.
The next logical step in creating custom workflow activity for SharePoint is to override the Execute method of the workflow activity. Then add the relevant logic to the Execute method for creating a Survey List in the specified site with the specified survey list name.

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
CreateSurveyLibrary();
return ActivityExecutionStatus.Closed;
}
 
 
private void CreateSurveyLibrary()
{
using (SPSite oSPSite = new SPSite(SiteUrl))
{
using (SPWeb oSPWeb = oSPSite.RootWeb)
{
Guid ID = oSPWeb.Lists.Add(SurveyListName, SurveyListName + System.DateTime.Now.ToString(),
SPListTemplateType.Survey);
 
SPList oSPList = oSPWeb.Lists[ID];
oSPList.OnQuickLaunch = true;
oSPList.Update();
}
}
}
Create a strong name for the assembly ‘CreateActivityDemo’.
Right click on the CustomWorkflowActivityDemo project and Add ---> SharePoint Mapped Folder
Navigate to Template1033Workflow and Select it.
custom activity4



Create an XML file called ‘CreateActivityDemo.Actions’ under the workflow folder. Complete the definition of ‘CreateActivityDemo.Actions’.The definition of ‘.Actions’ file is responsible for making the custom workflow activity appear in the SharePoint Designer 2010.
<WorkflowInfo>
  <Actions Sequential="then" Parallel="and">
    <Action Name="Create Survey List"
        ClassName="CreateActivityDemo.CreateSurveyList"
        Assembly="CreateActivityDemo, Version=1.0.0.0,
           Culture=neutral, PublicKeyToken=38b1d60938e39f46"
        AppliesTo="all"
        Category="Sundar Activity">
      <RuleDesigner Sentence="Survey List Name %1 to site %2.">
        <FieldBind Field="SurveyListName" Text="Survey List Name"
           DesignerType="TextArea" Id="1"/>
        <FieldBind Field="SiteUrl" Text="Url of base site" Id="2"
           DesignerType="TextArea"/>
      </RuleDesigner>
      <Parameters>
        <Parameter Name="SurveyListName" Type="System.String, mscorlib"
      Direction="In" />
        <Parameter Name="SiteUrl" Type="System.String, mscorlib"
      Direction="In" />
      </Parameters>
    </Action>
  </Actions>
</WorkflowInfo>

Next, we need to add the assembly for custom workflow activity in the Package.
Double click on the Package.package
custom activity5
Click ‘Advanced’ in Package Designer.
Add a Safe Control for Workflow Activity Assembly ‘CreateActivityDemo’.
custom activity6
 
Create an authorized type entry for the CreateActivityDemo assembly (custom workflow activity assembly).
<authorizedType Assembly="CreateActivityDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=38b1d60938e39f46" Namespace="CreateActivityDemo"
 TypeName="*" Authorized="True" />
Deploy the Solution. Now we’ll see the custom activity ‘Create Survey List’ appearing in the SharePoint Designer 2010 under actions.

custom activity7

 

 

The custom workflow activity  ‘Create Survey List’ is ready to be tested.

 

Create a re-usable workflow and drop the ‘Create Survey List’ activity.

 

Set the Values for SiteUrl and SurveyListName.

custom activity8[5]

 

Start the Workflow.

 

custom activity 9

 

Now the Survey is created in the site with defined name.

 

custom activity 10

This completes the development of custom workflow activity.

Tuesday, 17 January 2012

Programmatically set properties on InfoPath controls

okeh, starting a new year with a tight shcedule. Once again tighting the ropes of hope towards a brighter future of sharepoint programming.

These are the new list of my work this week :

1.Search for out of range data-programmatically

2. Search on how to set background color of textbox to highlight the out of spec data

3. configure workflow to sent out emeail whenever a data is out of limit

4. create a new library to submit reports upon the  out of range data from engineerss

SO 

Since task number 1 is more or less done...below are the things related to task number 2... here are the things i need to know first..read read read!


Programmatically set properties on InfoPath controls

by S.Y.M. Wong-A-Ton | Filed under: InfoPath 2007
Learn why you can only use conditional formatting on controls to programmatically set properties to hide, disable, or change the color for InfoPath controls.



I’ve written about this before, but think that the topic lends itself for a repeat post, because I’ve seen many of the visitors to my site searching for answers to questions such as:
  • how to hide first row by programmatically infopath
  • how to change infopath textbox colour programmatically

Using conditional formatting to set properties

Whether you want to:
  • programmatically make an InfoPath control read-only
  • programmatically hide an InfoPath control
  • programmatically change the background color of an InfoPath control
  • programmatically change the color of the text in an InfoPath control
you have to use Conditional Formatting to do so.
Programming in InfoPath is different to programming in Visual Studio. InfoPath controls do not have properties you can set at run-time through code. The only properties you can set are properties that are inherent to XML nodes.

Checking the availability of properties on an InfoPath control

If you want to programmatically set a property such as Enabled, Visible, BackgroundColor, Color, ReadOnly, etc. you first have to check whether an equivalent InfoPath conditional formatting setting is available for such a property.
You can do this by:
  1. Double-clicking on the control to open its Properties dialog box.
  2. Look for a Conditional Formatting button on the Properties dialog box; it is usually located on the Display tab.
  3. Open the Conditional Formatting dialog box and check whether it offers a setting that you can use for the property you want to programmatically set.

Creating a hidden field to use for setting properties through code

The logic behind using a hidden field to programmatically set a property on an InfoPath control is that you have to create a condition so that the conditional formatting on the control can be activated. And one way of doing this is by programmatically setting the value of a field on which the conditional formatting depends.
And since the field you’d be using is only to manipulate the visual aspects of controls, you don’t want users to actually see this field, which is why you should make it hidden.
I thought it would be good to show you step-by-step how to implement such a solution, so have gone ahead and written an article on how to programmatically hide the first row of a repeating table in infopath. Enjoy!


UPDATE

with the help of my very skillful friends called Ms."copy all rules" and also Mr. "paste", i have now done for 2nd task... hahaha..let's proceed to the next task... :D

For the third task i'll be referring to this note. From : http://www.bizsupportonline.net/browserforms/send-email-infopath-browser-form-sharepoint.htm 

How to send email from an InfoPath browser form in SharePoint



Learn which options are available for InfoPath to send email through an InfoPath form that is running in InfoPath Forms Services in SharePoint.


4 Ways to send data through email from an InfoPath form

Excluding methods which are available within SharePoint (but not within InfoPath) to send email such as sending email through an ItemAdded event handler or through a workflow, there are 4 ways to send email from an InfoPath form, which is running in InfoPath Forms Services in SharePoint:

  1. Use Rules with an email submit data connection.
  2. Programmatically send an email through an EmailSubmitConnection object.
  3. Use the SendEmail method of the SPUtility object in SharePoint.
  4. Use the MailMessage and SmtpClient classes in the System.Net.Mail namespace.
The first 3 methods require you to install and configure an SMTP server for SharePoint. The last method only requires an SMTP server that has anonymous access enabled.
All of the methods described in this article make use of an InfoPath form template that has 4 Text Box controls named toAddress, fromAddress, subject, and body, and one Button control which is used to send email.

1. Use Rules to send email in InfoPath

Add an email submit data connection named Email Submit to the InfoPath form template, and then add a Rule on the button that says:
Submit using a data connection: Email Submit Advantages:

  • You do not have to give the InfoPath form template full trust.
Disadvantages:

  • You have to configure outgoing email for SharePoint.
  • You cannot specify a From email address; the email address you configured for outgoing email in SharePoint will be used as the From email address.
  • You cannot attach files other than the InfoPath form itself to the email.

2. Use an EmailSubmitConnection to send email in InfoPath

Add an email submit data connection named Email Submit to the InfoPath form template, and then add the following C# code to the Clicked event handler for the button:
XPathNavigator root = MainDataSource.CreateNavigator();

string toAddress = root.SelectSingleNode("//my:toAddress",
  NamespaceManager).Value;
string fromAddress = root.SelectSingleNode("//my:fromAddress",
  NamespaceManager).Value;
string subject = root.SelectSingleNode("//my:subject",
  NamespaceManager).Value;
string body = root.SelectSingleNode("//my:body",
  NamespaceManager).Value;

EmailSubmitConnection conn =
  (EmailSubmitConnection)DataConnections["Email Submit"];
conn.To.SetStringValue(toAddress);
conn.Subject.SetStringValue(subject);
conn.Introduction = body;
conn.EmailAttachmentType = EmailAttachmentType.None;
conn.Execute();
Advantages:

  • You do not have to give the InfoPath form template full trust.
Disadvantages:

  • You have to configure outgoing email for SharePoint.
  • You cannot specify a From email address; the email address you configured for outgoing email in SharePoint will be used as the From email address.
  • You cannot attach files other than the InfoPath form itself to the email.

3. Use SPUtility.SendMail to send email in InfoPath

Add a reference to the SharePoint DLL to your InfoPath form template project and then add the following using statements to the FormCode.cs file:
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities; Add the following C# code to the Clicked event handler for the button:
XPathNavigator root = MainDataSource.CreateNavigator();

string toAddress = root.SelectSingleNode("//my:toAddress",
  NamespaceManager).Value;
string fromAddress = root.SelectSingleNode("//my:fromAddress",
  NamespaceManager).Value;
string subject = root.SelectSingleNode("//my:subject",
  NamespaceManager).Value;
string body = root.SelectSingleNode("//my:body",
  NamespaceManager).Value;

SPWeb web = SPContext.Current.Web;
bool result = SPUtility.SendEmail(
  web, false, false, toAddress, subject, body); Disadvantages:

  • You must give the InfoPath form template full trust and sign it with a digital certificate.
  • You have to configure outgoing email for SharePoint.
  • You cannot specify a From email address; the email address you configured for outgoing email in SharePoint will be used as the From email address.
  • You cannot attach files to the email.

4. Use System.Net.Mail classes to send email in InfoPath

Add the following using statement to the FormCode.cs file:
using System.Net.Mail; Add the following C# code to the Clicked event handler for the button:
XPathNavigator root = MainDataSource.CreateNavigator();

string toAddress = root.SelectSingleNode("//my:toAddress",
  NamespaceManager).Value;
string fromAddress = root.SelectSingleNode("//my:fromAddress",
  NamespaceManager).Value;
string subject = root.SelectSingleNode("//my:subject",
  NamespaceManager).Value;
string body = root.SelectSingleNode("//my:body",
  NamespaceManager).Value;

using (MailMessage msg = new MailMessage(fromAddress, toAddress))
{
  msg.Subject = subject;
  msg.Body = body;
  msg.IsBodyHtml = false;

  SmtpClient smtp = new SmtpClient("<your_smtp_server_name>");
  smtp.Send(msg);
}
Advantages:

  • You do not have to configure outgoing email for SharePoint.
  • You can specify a From email address.
  • You can attach files other than the InfoPath form to the email.
Disadvantages:

  • You must give the InfoPath form template full trust and sign it with a digital certificate.

Conclusion

You can use Rules, an EmailSubmitConnection, the SPUtility.SendEmail method, or classes in the System.Net.Mail namespace to submit or send email in InfoPath, but only the last method provides you with total control over the From email address and email attachments.
The method you choose to use InfoPath to send email will depend largely on whether you want to or can write code or not, what you would like to include in emails you send, and whether you require to include attachments and/or have control over the From email address.

Related InfoPath Articles:



i'll be using 2nd way. In which i want to attach the form in the email. So, in the code line :
conn.EmailAttachmentType = EmailAttachmentType.None;


I'll change none to Xml. Why? This is the explanation from msdn :
Set to EmailAttachmentType.Xml to send only the form file (.xml). Set to EmailAttachmentType.XmlXsn to send the form file (.xml) along with its associated form template file (.xsn).
but then, i got this error : "KeyNotFoundException" . Through googling session i found this workaround :

Error message when you try to debug an InfoPath form project that is built by using VSTO or VSTA: "System.Collections.Generic.KeyNotFoundException"

SYMPTOMS

When you try to debug and test an InfoPath form project that contains command line arguments, you receive the following error message:
System.Collections.Generic.KeyNotFoundException
The given key was not present in the dictionary.
You receive the error message if the InfoPath form project is built by using Microsoft Visual Studio Tools for Office System (VSTO) or Microsoft Visual Studio Tools for Applications (VSTA).

WORKAROUND

VSTO

To work around this issue in a VSTO project, follow these steps:
  1. In Visual Studio, click ProjectName Properties on the Project menu, and then click Debug.
  2. In the Start Action section, select Start external program, and then locate the Infopath.exe file.
  3. In the Start Options section, type the following in the Command line arguments box:
    /preview "Path\manifest.xsf" /sampledata "Path\template.xml" /viewname "View 1" /inputparameters "Parameter"
    Note The view name may not be "View 1." You must verify the view name in the project.

    Parameter is the placeholder for the parameter that you want to pass.
  4. Press F5 to debug the project.

VSTA

To work around this issue in a VSTA project, follow these steps:
  1. Create a new XML file that is based on the InfoPath form template. The InfoPath form template is an .xsn file.
  2. Save the XML file as Test.xml.
  3. Click Start, click Run, type InfoPath "Path\Test.xml" /inputparameters "Parameter" in the Open box, and then click OK.
adehhh but then...i don't understand the instruction..kih kih kih