Tuesday, 17 April 2012

Can't open the default.aspx page in SharePoint 2007 Designer

Hi I tried to open my SharePoint 2007 default  page in the SharePoint page but it can't open the page.
It gives the following error.

"soap:ServerServer was unable to process request. ---> A Web Part or Web Form Control on this Web Part Page cannot be displayed or imported because it is not registered as safe on this site. You may not be able to open this page in an HTML editor that is compatible with Microsoft Windows SharePoint Services, such as Microsoft Office SharePoint Designer. To fix this page, contact the site administrator to have the Web Part or Web Form Control configured as safe. You can also remove the Web Part or Web Form Control from the page by using the Web Parts Maintenance Page. If you have the necessary permissions, you can use this page to disable Web Parts temporarily or remove personal settings. For more information, contact your site administrator."

By do the simple steps we can clear this one
  1. Open you home default page or faulty page in the browser by: http://site:portnumber
  2. add "?contents=1"  like "http://site:portnumber?contents=1"
  3. Now you can view the webpart maintenance page
  4. Close the unwanted and error webpart
  5. Now you can open the page in sharepoint designer.
Happy Coding :) 

Thursday, 12 April 2012

Trying to use an SPWeb object that has been closed or disposed and is no longer valid

I tried to create website which is mostly deals with SharePoint list...   So I planed to minimize the resource usage by using the 'using' statement for the SPSite and SPWeb.

I create SPSite and SPWeb where I need. 

Finally I face the error

Trying to use an SPWeb object that has been closed or disposed and is no longer valid

 I check with the microsoft website

 http://social.technet.microsoft.com/Forums/en/sharepoint2010setup/thread/383931c6-3724-40ff-8ae8-7f26d6db1c92


They suggest don't dispose SPSite or SPWeb including SPContext.SPSite or SPContext.SPWeb also...

I remove the using statement and define the SPSite at the time on initialization by

SPSite MySite= new SPSite(SPContext.Current.WebUrl);

SPWeb MyWeb=null;

  and define the SPWeb in the constructor by 

 MyWeb=MySite.OpenWeb();

 Great now all working fine...

 Happy Coding :)

FatalError: Failed to compare two elements in the array

I tried to export my site by using STSADM

stsadm -o export -url <url> -filename <filelocation>


But I received the following error 
[4/12/2012 4:05:49 PM]: Start Time: 4/12/2012 4:05:49 PM.
[4/12/2012 4:05:49 PM]: Progress: Initializing Export.
[4/12/2012 4:05:49 PM]: Progress: Starting Export.
[4/12/2012 4:05:49 PM]: Progress: Calculating Objects to Export.
[4/12/2012 4:05:50 PM]: Progress: Serializing Objects to Disk.
[4/12/2012 4:05:50 PM]: Progress: Starting to process objects of type Site.
[4/12/2012 4:05:50 PM]: Progress: Finished processing objects of type Site.
[4/12/2012 4:05:50 PM]: Progress: Starting to process objects of type Web.
[4/12/2012 4:05:50 PM]: Progress: Exporting Web http://spmig:33322.
[4/12/2012 4:05:51 PM]: FatalError: Failed to compare two elements in the array.
   at System.Collections.Generic.ArraySortHelper`1.QuickSort[TValue](T[] keys, TValue[] values, Int32 left, Int32 right, IComparer`1 comparer)
   at System.Collections.Generic.ArraySortHelper`1.Sort[TValue](T[] keys, TValue[] values, Int32 index, Int32 length, IComparer`1 comparer)
   at System.Collections.Generic.ArraySortHelper`1.Sort(T[] items, Int32 index, Int32 length, IComparer`1 comparer)
   at System.Array.Sort[T](T[] array, Int32 index, Int32 length, IComparer`1 comparer)
   at System.Collections.Generic.List`1.Sort(Int32 index, Int32 count, IComparer`1 comparer)
   at System.Collections.Generic.List`1.Sort(IComparer`1 comparer)
   at Microsoft.SharePoint.Deployment.WebSerializer.GetDataFromObjectModel(Object obj, SerializationInfo info, StreamingContext context)
   at Microsoft.SharePoint.Deployment.DeploymentSerializationSurrogate.GetObjectData(Object obj, SerializationInfo info, StreamingContext context)
   at Microsoft.SharePoint.Deployment.XmlFormatter.SerializeObject(Object obj, ISerializationSurrogate surrogate, String elementName, Boolean bNeedEnvelope)
   at Microsoft.SharePoint.Deployment.XmlFormatter.Serialize(Stream serializationStream, Object topLevelObject)
   at Microsoft.SharePoint.Deployment.ObjectSerializer.Serialize(DeploymentObject deployObject, Stream serializationStream)
   at Microsoft.SharePoint.Deployment.SPExport.SerializeObjects()
   at Microsoft.SharePoint.Deployment.SPExport.Run()
*** Inner exception:
Failed to find the XML file at location '12\Template\Features\DenyAdd\feature.xml'
   at Microsoft.SharePoint.SPXmlDocCache.GetGlobalXmlDocumentCore(String pathXml, Boolean bFeature)
   at Microsoft.SharePoint.SPXmlDocCache.GetGlobalXmlDocument(String pathAllFeaturesRelativeXml)
   at Microsoft.SharePoint.Administration.SPFeatureDefinition.EnsureGlobalDefinition()
   at Microsoft.SharePoint.Administration.SPFeatureDefinition.get_Scope()
   at Microsoft.SharePoint.Administration.SPFeatureDefinition.ActivationDependencyComparer.System.Collections.Generic.IComparer<Microsoft.SharePoint.Administration.SPFeatureDefinition>.Compare(SPFeatureDefinition featdef1, SPFeatureDefinition featdef2)
   at Microsoft.SharePoint.Deployment.WebSerializer.ExportFeatureComparer.System.Collections.Generic.IComparer<Microsoft.SharePoint.Deployment.ExportObject>.Compare(ExportObject exportObject1, ExportObject exportObject2)
   at System.Collections.Generic.ArraySortHelper`1.QuickSort[TValue](T[] keys, TValue[] values, Int32 left, Int32 right, IComparer`1 comparer)
[4/12/2012 4:05:51 PM]: Progress: Export Completed.
[4/12/2012 4:05:51 PM]: Finish Time: 4/12/2012 4:05:51 PM.
[4/12/2012 4:05:51 PM]: Completed with 0 warnings.
[4/12/2012 4:05:51 PM]: Completed with 1 errors.


 I understood there is error in the feature which is already deployed in my website.  But I cant find which the faulty one.  

Finally I found this tool in CodePlex... Feature Admin V2.0  ...   

It is great we simply find the faulty feature and remove it .....
Now it is working fine....
happy coding:)
 
 
 

Monday, 9 April 2012

How to create and send outlook apointment in c# without any warning from Outlook

I received a requirement that send outlook appointment to the attendees of the meeting automatically after they booked the meeting.    
For that I found a solution to send a outlook appointment to the attendees.

Please add reference 'Microsoft.Office.Interop.Outlook'  Verson 11


private void test(string name, string location, string startTime, string endTime, string body, string email)
{
  Microsoft.Office.Interop.Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application(); // creates new outlook app
            Microsoft.Office.Interop.Outlook.AppointmentItem oAppointment = (Microsoft.Office.Interop.Outlook.AppointmentItem)outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem); // creates a new
            oAppointment.Subject = "Meeting""; // set the subject
            oAppointment.Body = "This is important"; // set the body
            oAppointment.Location = "NewYork"; // set the location
            oAppointment.Start = Convert.ToDateTime(startTime); // Set the start date
            oAppointment.End = Convert.ToDateTime(endTime); // End date
            oAppointment.ReminderSet = true; // Set the reminder
            oAppointment.ReminderMinutesBeforeStart = 15; // reminder time
            oAppointment.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh; // appointment importance
            oAppointment.BusyStatus = Microsoft.Office.Interop.Outlook.OlBusyStatus.olBusy;
            oAppointment.Save();
            Microsoft.Office.Interop.Outlook.MailItem mailItem = oAppointment.ForwardAsVcal();
            // email address to send to
            mailItem.To = email;
            // send
            mailItem.Send();
        }

Now the appointment was sending successfully.....

Important note you must configure you outlook in your machine because the from address is automatically fetched from the outlook account.

But I received a warning message like 'A program is trying to send an e-mail message on your behalf. If this is unexpected, click
deny and verify you antivirus software is up-to-date.'

This is terrible because the administrator of the server is not responsible to click allow or deny each and every time.

To stop this please follow the steps;
In outlook 2007 
1. Go to Toools->Trust Center
2. Select 'Programatic Access'
3. There select 'Never warn me about suspicious access'  because my antivirus was expired...... so check your antivirus and select the first option i.e 'Warn me about suspicious access when my antivirus is in-active or out-of-date'

Happy Coding :) 

Saturday, 7 April 2012

How to import user profile from Active directory to Shared Service Provider in SharePonit 2007

I created the users in the Active Directory in Windows Server 2003 then added users to the SharePoint site.  But I cant get the information which all are given in the Active Directory user profile.

I found a way to solve this the steps are given....
1. Open SharePoint Central Administrator
2. Open Shared Service administrator(link in the left panel).
3. Click "User Profile and Properties" under "User Profile and MySite".
4. There you can see a link named "Start Full Import".
5. Wait until all profiles imported.
6. Restart IIS
7. Go to Services and restart the "Windows SharePoint Services Timer"
8. Now you get all information in the site and Visual Studio also.

Happy Coding :)




Friday, 6 April 2012

Add Person/Group field to a SharePoint list from Webpart

I created a new list with person/group field as follows
Then create a WebPart with checkbox list which displays the users and button to add user to the list.
The following code explains how to do this.....

formula to add a user
<UserID>;#<UserLoginName>


using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;

namespace userselect
{
    [Guid("cdcee41f-cb36-42eb-b2d8-36af57fbcbd8")]
    public class userselect : Microsoft.SharePoint.WebPartPages.WebPart
    {
        private bool _error = false;
        private string _myProperty = null;
        Dictionary<int,string> UserInfo= new Dictionary<int,string>();
        Button AddUser;
        TextBox txtInfo;
        CheckBoxList UserList;
        public userselect()
        {
            this.ExportMode = WebPartExportMode.All;
        }
   protected override void CreateChildControls()
        {
            if (!_error)
            {
                try
                {

                    base.CreateChildControls();
                    UserList = new CheckBoxList();
                    Get_UserList();
                    UserList.ID = "UserList";
                    UserList.DataSource =UserInfo;
                    UserList.DataValueField = "Key";
                    UserList.DataTextField = "Value";
                    UserList.DataBind();
                    Controls.Add(UserList);

                    AddUser = new Button();
                    AddUser.ID = "AddUser";
                    AddUser.Text = "Add User";
                    AddUser.Click += new EventHandler(AddUser_Click);
                    this.Controls.Add(AddUser);

                 }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
            }
        }

        void AddUser_Click(object sender, EventArgs e)
        {
        string temp=string.Empty;
        SPSite site = new SPSite("http://url");
        SPWeb web = site.OpenWeb();

            for (int index = 0; index < UserList.Items.Count; index++)
            {
                if (UserList.Items[index].Selected)
                {
                int id=int.Parse(UserList.Items[index].Value);
                temp = id.ToString()+";#"+web.Users.GetByID(id).LoginName+";#";
               }
            }
            txtInfo.Text = temp;
//remove the extra symbol
            if (temp.EndsWith(";#"))
            {
                temp = temp.Substring(0, temp.Length - 2);
            }

            SPList list = web.Lists["newlist"];
            SPListItem item = list.Items.Add();

            item["Title"] = "from sugu";
            item["user"] = temp;
            item.Update();


        }

        /// <summary>
        /// Ensures that the CreateChildControls() is called before events.
        /// Use CreateChildControls() to create your controls.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            if (!_error)
            {
                try
                {
                    base.OnLoad(e);
                    this.EnsureChildControls();

                    // Your code here...
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
            }
        }

        /// <summary>
        /// Clear all child controls and add an error message for display.
        /// </summary>
        /// <param name="ex"></param>
        private void HandleException(Exception ex)
        {
            this._error = true;
            this.Controls.Clear();
            this.Controls.Add(new LiteralControl(ex.Message));
        }


        private void Get_UserList()
        {
            UserInfo.Clear();
           
            SPSite site = new SPSite("http://url");
            SPWeb web = site.OpenWeb();
           // I need the users only from the viewers group
            SPGroup group = web.Groups["Viewers"];
           
            foreach (SPUser user in group.Users)
            {
                UserInfo.Add(user.ID, user.Name);
               
            }
          
        }

        protected override void Render(HtmlTextWriter writer)
        {
            base.Render(writer);
        }
    }
}


Happy coding :)