Tuesday, December 14, 2010

For more information about Sharepoint :

http://www.apnamotihari.com/e-learning/sharepoint1.htm

http://kksrivastava.blogspot.com/

http://anandadhi23.blogspot.com

http://vasanthmoss.blogspot.com

http://www.kamalasekar.blogspot.com/

copy Entire list item using workflows

This code is used for copying entire list item in to another list using workflows

 private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
 {
SPSite mySourceSite = new SPSite("http://fivenumber:5/");
                SPWeb mySourceWeb = mySourceSite.OpenWeb();
                SPList mySourceList = mySourceWeb.Lists["Source List"];
                SPQuery mySourceListQuery = new SPQuery();
                mySourceListQuery.Query = "" +
                                "" +
                                "" +
                                "" +
                                "";
                SPListItemCollection mySourceItemColl = mySourceList.GetItems(mySourceListQuery);
                int count = 0;
                foreach (SPListItem mySourceListItem in mySourceItemColl)
                {
                    string SourceEmpId = mySourceListItem["Employee Id"].ToString();
                    string SourceEmpName = mySourceListItem["Employee Name"].ToString();
                    string SourceDesig = mySourceListItem["Designation"].ToString();
                    string SourceAge = mySourceListItem["Age"].ToString();

                    SPSite myDestinationSite = new SPSite("http://fivenumber:50");
                    SPWeb myDestinationWeb = myDestinationSite.OpenWeb();
                    SPList myDestinationList = myDestinationWeb.Lists["Destination List"];
                    SPListItem myDestinationListItem = myDestinationList.Items.Add();

                    myDestinationListItem["Employee Id"] = SourceEmpId;
                    myDestinationListItem["Employee Name"] = SourceEmpName;
                    myDestinationListItem["Designation"] = SourceDesig;
                    myDestinationListItem["Age"] = SourceAge;
                    myDestinationWeb.AllowUnsafeUpdates = true;
                    myDestinationListItem.Update();
                    myDestinationWeb.AllowUnsafeUpdates = false;
                    count++;
                    Console.WriteLine(count+" item(s) copied");
                }
               
            }


Try This!!!!!!!!!!!
          

copy current list item from one list to another using visual studio workflows

 private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
        {
            SPSite mySourceSite = new SPSite("http://productionsrv:2012/Lists/anandh/AllItems.aspx/");
                SPWeb mySourceWeb = mySourceSite.OpenWeb();
                SPList mySourceList = mySourceWeb.Lists["anandh"];
                SPListItem mySourceListItem = workflowProperties.Item;

                //SPQuery mySourceListQuery = new SPQuery();
                //mySourceListQuery.Query = "";
                //SPListItemCollection` mySourceItemColl = mySourceList.GetItems(mySourceListQuery);
                ////int count = 0;
                //foreach (SPListItem mySourceListItem in mySourceItemColl)
                //{
                    string SourceEmpId = mySourceListItem["emp"].ToString();
                    string SourceEmpName = mySourceListItem["emp name"].ToString();
                    string SourceDesig = mySourceListItem["emp id"].ToString();
                    string SourceAge = mySourceListItem["salary"].ToString();

                    SPSite myDestinationSite = new SPSite("http://productionsrv:2012/Lists/kamal/AllItems.aspx/");
                    SPWeb myDestinationWeb = myDestinationSite.OpenWeb();
                    SPList myDestinationList = myDestinationWeb.Lists["kamal"];
                    SPListItem myDestinationListItem = myDestinationList.Items.Add();

                    myDestinationListItem["emp"] = SourceEmpId;
                    myDestinationListItem["emp name"] = SourceEmpName;
                    myDestinationListItem["emp id"] = SourceDesig;
                    myDestinationListItem["salary"] = SourceAge;
                    myDestinationWeb.AllowUnsafeUpdates = true;
                    myDestinationListItem.Update();
                    myDestinationWeb.AllowUnsafeUpdates = false;
                    //count++;
                    //Console.WriteLine(count+" item(s) copied");
                //}
               
            }
           
 Try this,it will work

Monday, December 13, 2010

workflow in sharepoint

copy items in one document library to another library using  sequential wokflows

This is step by step instruction to create workflows in visual tudio 2008

   -> open the visual studio 2008
  ->  select new project and then select  sharepoint sequential workflow

Type this coding :


// Get the item the workflow is running on
SPListItem item = workflowProperties.Item;


// Set the name of the document library and site
// where to copy the document to
string siteUrl = "
http://<ServerName>/<SiteName>/";
string libName = "DocLibForCopies";

// Open the site
using (SPSite site = new SPSite(siteUrl))
{
  using (SPWeb web = site.OpenWeb())
  {
    if (item.File != null)
    {
      // Copy the document to the library
      SPFolder library = web.Folders[libName];
      library.Files.Add(
        item.Name, item.File.OpenBinary());
      library.Update();
    }
  }
}

i hope you will get the solution