Sunday 22 March 2015

How To Debug Custom Timer Job

Debugging a custom timer job is very easy.

1. Deploy your code.
2. Now go to debug and select "Attach to process".
3. Search for OWSTIMER.exe.
4. Select  OWSTIMER.exe and click on Attach.
5. Now Wait for some time, the debugger will apply.

Note: If OWSTIMER.exe not found then what???

Go to run and search enter services.msc.

Search for SharePoint 2010 Timer and start that, then repeat the above process.

Custom Timer Job In SharePoint 2010

Custom Timer Job In 2010-

I am going to illustrate how to create Custom Timer job in SharePoint 2010.

Task: Updating the Sql Server Database table after each minute from SharePoint List.

1. Create a SharePoint Project as a form Solution.
2. Take a class file "SpeedTimer.cs"


3. Copy and paste the following code:

-----------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint;
using System.Configuration;
using System.Web.Configuration;
using System.Data.SqlClient;
using System.Data;
namespace SharePointProject2
{
    class SpeedTimer : SPJobDefinition
    {
         public SpeedTimer()

            : base()
        {

        }

         public SpeedTimer(string jobName, SPService service, SPServer server, SPJobLockType targetType)

            : base(jobName, service, server, targetType)
        {

        }
         public SpeedTimer(string jobName, SPWebApplication webApplication)

            : base(jobName, webApplication, null, SPJobLockType.ContentDatabase)
        {

            this.Title = "Speed List Timer Job";

        }

         public override void Execute(Guid contentDbId)
         {

             // get a reference to the current site collection's content database
             SPWebApplication webApplication = this.Parent as SPWebApplication;

             SPContentDatabase contentDb = webApplication.ContentDatabases[contentDbId];

             // get a reference to the "ListTimerJob" list in the RootWeb of the first site collection in the content database

             SPList Listjob = contentDb.Sites[0].RootWeb.Lists["BackupTimerjobList"];

             //SPListItem newList = Listjob.Items.Add();

             //newList["Title"] = DateTime.Now.ToString();

             //newList.Update();


             //Fetch Configuration file
             Configuration config = WebConfigurationManager.OpenWebConfiguration("/", webApplication.Name);

             //// Read Connectin string
             string ConnectDB = config.ConnectionStrings.ConnectionStrings["ConnectDB"].ToString();



             SqlConnection con = new SqlConnection(ConnectDB);
             con.Open();

             foreach (SPListItem item in Listjob.Items)
             {

                 string str1 = "insert into listbackup (Title) values('" + item["Title"] + "')";
                 SqlCommand cmd = new SqlCommand(str1, con);
                 cmd.CommandType = CommandType.Text;
                 cmd.ExecuteNonQuery();


             }
             con.Close();
           
             // create a new list Item, set the Title to the current day/time, and update the item

           
         }
        

    }

}


4.  Right click on feature and click on Add Feature.
5. Select Scope as Site.
6. Now Right Click on your Feature and click on add event receiver.
7. Copy and paste the following code.
----------------------------------------------------------------------------------------------------------
using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Administration;

namespace SharePointProject2.Features.Feature1
{
    /// <summary>
    /// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
    /// </summary>
    /// <remarks>
    /// The GUID attached to this class may be used during packaging and should not be modified.
    /// </remarks>


    [Guid("2e8afeab-7a33-4da0-8a01-ab3e462f10b6")]
    public class Feature1EventReceiver : SPFeatureReceiver
    {
        const string List_JOB_NAME = "ListLogger";
        // Uncomment the method below to handle the event raised after a feature has been activated.

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSite site = properties.Feature.Parent as SPSite;

            // make sure the job isn't already registered

            foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
            {

                if (job.Name == List_JOB_NAME)

                    job.Delete();

            }

            // install the job

            SpeedTimer listLoggerJob = new SpeedTimer(List_JOB_NAME, site.WebApplication);

            SPMinuteSchedule schedule = new SPMinuteSchedule();

            schedule.BeginSecond = 0;

            schedule.EndSecond = 59;

            schedule.Interval = 1;

            listLoggerJob.Schedule = schedule;

            listLoggerJob.Update();

        }


        // Uncomment the method below to handle the event raised before a feature is deactivated.

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPSite site = properties.Feature.Parent as SPSite;

            // delete the job

            foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
            {

                if (job.Name == List_JOB_NAME)

                    job.Delete();

            }
        }


        // Uncomment the method below to handle the event raised after a feature has been installed.

        //public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        //{
        //}


        // Uncomment the method below to handle the event raised before a feature is uninstalled.

        //public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        //{
        //}

        // Uncomment the method below to handle the event raised when a feature is upgrading.

        //public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters)
        //{
        //}

    }
}

8. Now Deploy your code.

 




Sunday 8 March 2015

Insert, Update and Delete in SharePoint 2010 using C#


We can do insert, update, delete operations in SharePoint List using C# web part.
 This is very simple to insert, update and delete in custom list of SharePoint.

On button click event follow this code for Inserting data into SharePoint List.
Insert:

             SPWeb spweb = SPContext.Current.Web;     //open your site

             SPList splist = spweb.Lists["Student"];         // select your list
     
             SPListItem spitem = splist.Items.Add();

             int rno = txtRno.Text;

             string name = txtName.Text;

            string address = txtAddress.Text;

            spitem["RollNo"] = Convert.toInt32(rno);

            spitem["Name"] = name+"";

            spitem["Address"] = address +"";

            spitem.update();

Delete:

               int id= Convert.toInt32(ddlRno.Text);               // Select the id which you want to delete

               SPWeb spweb = SPContext.Current.Web;     //open your site

             SPList splist = spweb.Lists["Student"];         // select your list

             SPListItemCollection spcol = splist.items;
     
             SPListItem spitem = spcol.getItemById(id);

              spitem.delete();

Update:
               /*Opening web*/
                SPWeb web = SPContext.Current.Web;
                /* Accessing list from web by creating list object*/
                SPList lst = web.Lists["student"];

                int id = Convert.ToInt32(ViewState["id"]);

                /*getting items by id*/
                SPListItem item = lst.GetItemById(id);

                /*setting values to particular ids*/
                item["Name"] = txtName.Text;
                item["Contact no"] = txtContact.Text;
                item["Address"] = txtAddress.Text;
                item["Marks"] = txtMarks.Text;
                item.Update();
                bind();                        //binding gridview
                txtAddress.Text = "";
                txtContact.Text = "";
                txtMarks.Text = "";
                txtName.Text = "";
                lblMsg.Visible = true;
                lblMsg.ForeColor = Color.DarkGray;
                lblMsg.Text = "Updated";
                ViewState["id"] = "";

   






                    




             

             
           


Saturday 7 March 2015

Microsoft launches Office 2016 preview for Mac with full Retina support, OneDrive and SharePoint integration

Microsoft today launched a preview of Office 2016 for Mac. The test version of the productivity suite is free, doesn’t require you to register or sign in, and can be installed alongside Office for Mac 2011 — you can download it now from Office.com’s Mac preview page.
Office for Mac is now “powered by the cloud” so users can access their documents “anytime, anywhere, and on any device.” More specifically, the upcoming productivity suite integrates with Office 365, One Drive, One Drive for Business, and SharePoint so that you can access documents across personal and work accounts from various devices by just signing in with your Office account.
Microsoft says the new apps offer full Retina display support with thousands of Retina-optimized graphics. While Office 2011 for Mac included some Retina support, it was mainly focused on the canvas (where the document is displayed) and the most common parts of the user interface.
Eric Wilfrid, general manager of Microsoft’s Macintosh Business Unit, told VentureBeat there are now “no more dark areas” in terms of Retina support. This is possible because Microsoft has now completely switched over to Apple’s Cocoa APIs.
In that same vein, Office 2016 for Mac requires OS X 10.10 Yosemite. This is undoubtedly good news for Apple as those still on older OS X versions will have yet another incentive to upgrade.

Microsoft’s preview includes Word, Excel, PowerPoint, OneNote, and Outlook. That said, only the first three are really new — this OneNote version is the same one that came out on February 19 and this Outlook version is the same one Office 365 users have already been using on their Macs.
For Word, Excel, and PowerPoint, the redesigned ribbon on OS X is now consistent across the various platforms that Office runs on (if a function is on the Insert tab on your Mac, it will be there on your Android tablet as well). There’s also a new task pane interface that Microsoft hopes will make it easier to position, resize, and rotate graphics, as well as the usual new themes and styles to help you quickly spiff up your documents.
Full screen view and even “little Mac affordances” like scroll bounce have been added as well. As Microsoft puts it, “It’s unmistakably Office — but thoughtfully designed to take advantage of the unique features of the Mac.”

Word

There aren’t too many changes specific to Word 2016. That said, the cloud integration will probably be most useful in this app: When you see “Updates Available,” just click it to see what your colleague or friend has changed in the document.
Co-authoring and threaded comments (also available in PowerPoint) are two powerful collaboration features that have been greatly improved. The former lets several collaborators simultaneously edit the same document from different devices, and the latter lets them easily track comments right next to relevant text while seeing who replied to whom and when.
Microsoft highlights the following three Word 2016 additions:
  • Navigation pane helps you track where you are in a document and move to points of interest.
  • Dictionary enhances reading and improves understanding.
  • The style pane allows you to visually apply and review styles already applied on your document.
For better or for worse, this release uses many more panes for various functions that require multiple actions from the user.

Excel

By far the biggest addition to Excel is the support for Windows keyboard shortcuts. While previous Mac combinations will still work, Excel 2016 also supports the same Windows shortcuts on the Mac, so moving between Microsoft’s and Apple’s operating systems should no longer be a problem.
Excel_2016_preview_for_Mac
The following Excel 2016 features are new:
  • Most Excel keyboard shortcuts are now consistent across Windows and Mac.
  • Analysis ToolPak includes all the statistical functions you need to do an in-depth analysis of your data.
  • Slicers let you repivot information to explore and share insights.
  • Print improvements include the ability to print to a single PDF file.
  • Formula Builder allows you to easily leverage the power of Excel formulas.
  • With autocomplete, Excel is one step ahead of you — improving your efficiency and improving the accuracy of your data input.
From what we saw in the demo Wilfrid gave us, slicers seems like a useful data analysis tool for cutting through large volumes of data to spot patterns. The Analysis ToolPak goes even further with more advanced statistical functions, including moving averages and exponential smoothing.

PowerPoint

The most useful PowerPoint 2016 feature is the Presenter view. This is what you’ll have open when you’re actually showing your PowerPoint presentation — it displays the current slide and any corresponding notes, the next slide so you can glance and prepare accordingly, a timer, and even all the slides at the bottom for easy skimming.
PowerPoint 2016 adds the following:
  • With Presenter View you can see the notes accompanying your slide as well as a film strip of upcoming slides.
  • This allows you to focus on your audience while presenting on a second screen.
  • New slide transitions add a wider range of options to create more visual interest in your presentations.
  • The conflict resolution experience allows you to visually compare conflicts, so you can confidently choose the right version to keep.
  • Animation pane helps you manage your animations in one place.
Again, there already was an Animations tab in PowerPoint for Mac, but now there’s a specific pane that lets you play around even more.

OneNote and Outlook

Again, neither of these two apps are technically new. They were both released for Mac in 2014 and have received multiple updates since.
Still, Outlook was only available to Office 365 subscribers until now. Anyone willing to try preview software can give Outlook for Mac a go for free, though after general availability you’ll naturally have to start paying.
                                       OneNote_2016_preview_for_Mac
As for OneNote, the app has been free for about a year. You do, however, need an Office 365 subscription to access SharePoint notebooks.
In short, this is an opportunity to give the company feedback on what you, as a Mac user, like or dislike about these two apps. Getting on the preview also means you’ll get regular updates.

What’s next

Microsoft says the Office 2016 preview for Mac will be updated “regularly” — you will receive a notification from the Office for Mac Auto-Update tool. Every build will expire roughly 60 days after it’s released, and the last preview build will continue to function for roughly a month after the official launch.
As for the launch, Microsoft is currently slating general availability for “this summer.” Pricing and packaging details “will show up later,” Wilfrid told us.

Sunday 1 March 2015

FBA(Form Based Authentication) configuration in SharePoint 2010

Simple FBA Configuration
I am going to share my first 'Form Based Authentication' experience with you. I am going to illustrate how you can configure FBA with SharePoint 2010. 

            If you will follow each and every step as follows, you will get success in only one attempt.
The steps we are going to take into action are:-

1. Create a database using aspnet_regsql.exe application.
2. Create a logging user from SQL SERVER.(Compulsory)
3. Add that logging user to FBA Database security section.
4. Setting up Role Manager, Membership Manager and Connection String into SharePoint central admin v4, SharePoint security token, and into your Web into which you wanted to setup FBA.
5. Add some users

That's it.

Lets do the above steps.

1.  Create a database using aspnet_regsql.exe application.

     Follow the link- 

   a.    C->Windows->Microsoft.NET->Framework->v2.0.50727


and search for aspnet_regsql.exe and open it.


b. Click on Next    


c. Select configure Sql  Server for application services and click on Next button.

 d. Fill your sql server name or if it showing default then its OK, type your database name and click on Next.

e.  Click Next  and Finish .


2. Create a logging user from SQL SERVER.

    Don't forget to select  sql server authentication.(If not visible then select view image by right click)

   
Go to your database security tab and open that:
Select db_owner and click OK


3. Configure Central Admin Web Site to use SQL Membership Provider

SharePoint web sites out of the box are configured to use Active Directory.  So you may be wondering why we’re configuring Central Admin to use FBA when we don’t really want to login in as an FBA user.  Well, we actually don’t want to configure it to to login as a forms user, but we do need to be able to add users from out membership database when configuring site collection admins, and the like.
So all we want to do is tell the Central Admin web application to use our SQL membership provider as well as AD, so when you use the people picker to select users, it will provide results from our membership database.
Open IIS Manager on the WFE server (if more than one, then this needs to be done on every FWE that has Central Admin.  The same goes for the proceeding steps for the other web applications).
Select the SharePoint Central Administration v4 site.  On the Home Page, you’ll see many options for ASP.NET and IIS.  The ones we’re concerned with are
Open the Connection Strings Page.  Under Actions menu on the right, select Add… to create a new connection string.  Provide the details for the membership database for the new connection string.
Add Role Provider
Go back to the Web Application page and open up Providers page.  Here we will create a provider for Roles and Users.  Set feature to .NET Roles and click Add… in the Actions pane to add a new role provider.  I called it FBARoleProvider and selected the right type and connection string.
Ensure you provide an ApplicationName so the provider knows what uses to authenticate.
Add Membership Provider
Now set feature to .NET Users and click Add… from the actions pane to add a membership provider.
Select the correct type and connection string, and whatever behaviors you choose.
That’s it for the providers for Central Admin.


4. Configure Secure Store Web Service to use SQL Membership Provider

Everything we did for Central Admin site, we are going to do for the SecurityTokenServiceAppliaation which is in the SharePoint Web Services application.
Without redo’ing all the steps:
  • Create the connection string
  • Add the .NET role provider
  • Add the .NET users provider
    Verify connection by editing config.xml.

4. Create Extranet Web Application

Ok, finally we are ready to create our web application (called SharePoint – FBA) that will use FBA authentication.
In Central Admin, Select the Application Management page, and select Manage web applications.  Select New from the ribbon to create a new web application.
Select Claims Based Mode Authentication as Authentication Type.  Select values for all the other options until you get to the “Enable Forms Based Authentication”.
Add the values we created earlier in the section “Enable Forms Based Authentication” for role and membership provider.
Once the application is created, we should create a site collection.
Create Site Collection
Go to the Create Site Collection page from the Manage Applications section in Central Admin.  Select the team (or blank, or whichever you choose) template then select the site collection administrator.  At this point, we should be able to select from our SQL membership users.  Enter a user you know exists in the membership database and see if you can resolve the names.



I have a user with the same name in both AD and SQL, so I know I am hitting both.
Note: I jumped ahead here and added users through IIS Manager.  If you have been following this article to the letter, then you will obviously not see users in your membership database.  Do not worry about this piece for now, as you will add users to your membership store later.
At this point we have told SharePoint what role providers to use for the web app, but we still need to configure the web app through IIS manager to bind the providers.
Configure Membership Providers for Web App through IIS
In IIS Manager, browse to the new site SharePoint – FBA. For our new FBA site we need to do the following:
  • Add connection string
  • Add Providers for members and roles
  • Configure .NET Roles
  • Configure .NET Users
  • Set Authentication to Forms and Integrated
  • Add User as Site Collection Admin

    1. Add Connection String
    Same as we have done before.
    Note: we could potentially just do this for the machine, and not have to do it for every web application.  I prefer to do it for every web app, as I’ve had mixed results otherwise.
    2. Add role and user providers
    Again, same as what we did before.  Open Providers page and add an entry for our role and user providers.

    3. Configure .NET Roles
    This and the next steps are not required for the other two web applications we configured (Central Admin and SSS).
    Open the .NET Roles page for our web application.  You will receive a warning that the default role provider is not trusted.  WE just need to set our default role provider to FBARoleProvider.


    We do not have any roles in our database at this point, so let’s create two (StandardUser, SuperUser) by clicking Add… in the actions pane.
    4. Configure .NET Users
    Now we need to do the same for .NET Users.  Open the .NET Users page.  You will get a similar warning saying the default is not trusted.  Set the default provider to FBAMembershipProvider. If you had members in the database, you would now see them listed.  Assuming you don’t let’s add some.  Click Add… from the Actions pane to add users, and assign them roles.

    5. Set Authentication SharePoint should have done this when you created the web application, but let’s confirm.  From the web application home page in IIS Manager, select Authentication under the IIS section. Confirm that the web application has both Integrated and Forms enabled. 6. Add User as Site Collection Admin
    Now that we have everything hopefully configured correctly, we can go back to SharePoint Central Admin and add our new user as the Site Collection Administrator.  From Central Admin Application Management page, click Change site collection administrators.  Select SharePoint – FBA root site collection, and add our new user.
    Now lets test all this business by trying to login.  Browse to your site and select to login as a forms user.

    What the…?!  I am authenticated ok, but am not allowed in, even though I’m a site collection admin?!
    Caveat Here’s the caveat – In order for you to use IIS Manager to manage your SQL users, you need to set the default provider to our Forms provider, i.e. FBAMembershipProvider.  In order for it to work we need to set it to the SharePoint claims provider.  Go back to .NET Users and reset the default provider to “i” which is for the Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider
    You could work around this by creating another IIS web site, configure the same way you did for SharePoint – FBA, and use that for managing users.
    You should also check the default Role Provider for the web application and ensure that is set to “c”.  If this is set to the SQL provider that you created, you will get an unexpected error after you logon.
    Now let’s try to login again…