Monday, 18 June 2012

Error Helper

STEP 1: Create a class file like ErrorHelper.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace VCSB.INTRANET.BLL
{
   public class ErrorHelper
    {
        #region LoginName
        /// <summary>
        /// Get Currnet user Loginame
        /// </summary>
        public static string LoginName
        {
            get
            {
                SPSite spSite; SPWeb spWeb;
                using (spSite = new SPSite(SPContext.Current.Site.Url))
                {
                    using (spWeb = spSite.OpenWeb())
                    {
                        SPUser sUser = spWeb.CurrentUser;
                        //string str = sUser.Name + sUser.LoginName + sUser.Email + sUser.Groups.Count;
                        return sUser.LoginName;
                    }
                }
            }
        }
        #endregion

        #region Add
        public static void Add(string message, string stacktrace)
        {
            try
            {
                SPSite spSite; SPWeb spWeb; SPList spList;
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (spSite = new SPSite(SPContext.Current.Site.Url))
                    {
                        spSite.AllowUnsafeUpdates = true;
                        using (spWeb = spSite.OpenWeb())
                        {
                            spWeb.AllowUnsafeUpdates = true;
                            SPWeb objweb = spSite.OpenWeb();
                            spList = spWeb.Lists.TryGetList("ErrorLog");
                            if (spList != null)
                            {
                                SPListItem spListItem = spList.Items.Add();
                                spWeb.AllowUnsafeUpdates = true;
                                spListItem["ErrorMessage"] = Convert.ToString(message);
                                spListItem["StackTrace"] = Convert.ToString(stacktrace);
                                spListItem["LoginName"] = Convert.ToString(LoginName);
                                spListItem.Update();
                            }

                        }
                        spWeb.AllowUnsafeUpdates = false;
                    }
                    spSite.AllowUnsafeUpdates = false;
                });
            }
            catch { }
        }
        #endregion
    }
}
 

No comments:

Post a Comment

SharePoint online - Get List-item attachments and Display to div

Step 1 : Create a List ex: TestList and attach few images Step 2 : Copy and Pastet the below coding in App.js var  Items =  null ; ...