Showing posts with label Sharepoint 2007. Show all posts
Showing posts with label Sharepoint 2007. Show all posts

Friday, 27 July 2012

The request failed with HTTP status 417: Expectation failed when SharePoint calling .asmx web service

I tried to access a web method in a .asmx web service from SharePoint web service.
To add a web reference steps
  1. Add Service Reference
  2. Click Advance button in the window
  3. Click Add Web Reference in the next window
  4. Then paste the asmx path add give a reference name then click ok
After this I tried to call the web method but it gives the  The request failed with HTTP status 417 error  I tried with Google finally I found a link in Code Project
http://www.codeproject.com/Articles/94235/The-request-failed-with-HTTP-status-417-Expectatio

Steps to Resolve
  • We need to have this line of code before making any web requests:  
         System.Net.ServicePointManager.Expect100Continue = false
 
  • Add these lines to the application's configuration file (between <configuration> and </configuration>): 
     
    <system.net>
     <settings>
      <servicePointManager expect100Continue="false" />
     </settings>
    </system.net>
     
     
    Now Everything goes fine.
     
    Happy Coding :)  

Wednesday, 23 May 2012

Types of Deployment in SharePoint 2007

Who Needs Deployment?

Regarding the development environment, there are two types of SharePoint projects:
  • Single environment projects, where everything is configured and developed directly in the production environment;
  • Multiple environment projects, where all the development and configuration is done in a development environment, then possibly deployed to a testing environment, and finally deployed to the production environment.
Additionally, you can have two types of farms, in a SharePoint installment:
  • Single server farm, when there is only one SharePoint Server in the farm (although there can be additional SQL Servers);
  • Multiple server farm, when there are several SharePoint Servers, possibly with different server roles, in the farm.
For Single Server – Single Environment projects, which are the least common type, the developers don't really need to be concerned about deployment since everything is done on the same server. But for the other types of projects (Single Server – Multiple Environment, Multiple ServerSingle Environment and Multiple Server Multiple Environment) developers will need to deploy their work to the servers.

What Does Deployment Mean, in a SharePoint Sense?

In SharePoint, deployment means the necessary actions to install your software solution in a SharePoint environment, whether that solution consists of web parts, custom web controls, event handlers, custom web pages, or just master pages.
So, imagine you have created site columns and content types directly on the SharePoint UI, customized some master pages using SharePoint Designer and installed a few custom web parts on your Development Environment, and now you need to deploy this to the Testing Environment (and later on, to the Production Environment). You can choose from a few different deployment methods:
  • Stone Age Deployment. You do it all over again in the Testing Environment, and later you will repeat the procedure in the Production Environment. It's not hard to figure out this is a bad practice: probably you won't be able to repeat the tasks in the exact same order as you did before, and that might result in errors or in a Testing Environment that is not a replica of the Development Environment. Also, that means the developers must have administration access in all the environments, which is not always the case.
  • Backup/Restore Deployment. You perform a farm backup on the Development Environment and restore it in the Testing Environment. Although commonly used, it's not the best practice either: you must make sure all the assemblies, web.config modifications, and file system changes are present in the destination environment before you restore the backup. Also, you might have some problems if the environments are not in the same windows domain.
  • Content Deployment. You use SharePoint's content deployment paths and jobs. That can be a good solution, but it has some limitations: unless you are deploying a whole site collection, you'll need to make sure all the assemblies, web.config modifications, and file system changes are present in the destination environment before you restore the backup. Content deployment is targeted at "contents" and not at "structure", although some of the SharePoint structures are migrated with the contents. Also, both environments must be connected for automatic content deployment to work. You have the option to export a site collection to a .CAB file and import it in the destination environment using STSADM commands, but the same limitations apply.
  • Solution Deployment. You build SharePoint Features for all the objects you developed and pack them in one or more SharePoint Solutions. This is the recommended approach for structure deployment, since it allows for multiple server farm deployment, allows the deployment of assemblies, web.config modifications, files in file system folders as well as all SharePoint objects.

Friday, 18 May 2012

jQuery font issue in SharePoint

I tried to added jquery datepicker in the custom webpart finally added the datepicker.  After that I noticed in my SharePoint 2007 site menu style totally changed the font size of the menu became tiny.

The way to fix the problem is

1. Open the jquery style sheet demos.css
2. Remove the style
 table
 {
    font-size: 1em;
  }

now it is working fine.

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 :) 

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 :)




Tuesday, 11 October 2011

Configure outgoing e-mail settings (Office SharePoint Server)


Use this procedure to configure the default outgoing e-mail settings for all Web applications. You can override the default outgoing e-mail settings for specific Web applications by using the procedure that is described in Configure outgoing e-mail settings for a specific Web application (Office SharePoint Server).

Install and configure the SMTP service

Before you can enable outgoing e-mail, you must install the Internet Information Services (IIS) Simple Mail Transfer Protocol (SMTP) service. After determining which SMTP server to use, the SMTP server must be configured to allow anonymous access and to allow e-mail messages to be relayed. Additionally, the SMTP server must have Internet access if you want the ability to send messages to external e-mail addresses, or it must be able to relay authenticated e-mail to a server that has Internet access. The SMTP server that you use can be a server in the farm, or another server.

Install the SMTP service

The SMTP service is a component of IIS.

Install the SMTP service

  1. In Control Panel, click Add or Remove Programs.
  2. In Add or Remove Programs, click Add/Remove Windows Components.
  3. In the Windows Components Wizard, in the Components box, click Application Server, and then click the Details button.
  4. In the Application Server dialog box, in the Subcomponents of Application Server box, click Internet Information Services (IIS), and then click the Details button.
  5. In the Internet Information Services (IIS) dialog box, select the SMTP Service check box.
  6. Click OK to return to the Application Server dialog box.
  7. Click OK to return to the main page of the Windows Components Wizard.
  8. Click Next.
  9. When Windows has finished installing the SMTP service, on the Completing the Windows Components Wizard page, click Finish.

Configure the SMTP service

After installing the SMTP service, configure the service to accept relayed e-mail from servers in your farm.
You can decide to accept relayed e-mail from all servers except those you specifically exclude. Alternatively, you can block e-mail from all servers except those you specifically include. You can include servers individually, or in groups by subnet or domain.
By enabling both anonymous access and e-mail relaying, you increase the possibility that the SMTP server will be used to relay unsolicited commercial e-mail (spam). It is important to limit this possibility by carefully configuring your mail servers to help protect against spam. One way that you can do this is by limiting relaying to a specific list of servers or domain, and preventing relaying from all other servers.
Important Important:
Membership in the Administrators group on the local computer is required to complete this procedure.

Configure the SMTP service

  1. Click Start, point to All Programs, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.
  2. In IIS Manager, expand the server name that contains the SMTP server that you want to configure.
  3. Right-click the SMTP virtual server that you want to configure, and then click Properties.
  4. On the Access tab, under Access control, click Authentication.
  5. In the Authentication dialog box, under Select acceptable authentication methods for this resource, verify that Anonymous access is selected.
  6. Click OK.
  7. On the Access tab, under Relay restrictions, click Relay.
  8. To enable relaying from any server, under Select which computer may relay through this virtual server, select All except the list below.
  9. To accept relaying from one or more specific servers, follow these steps:
    1. Under Select which computer may relay through this virtual server, select Only the list below.
    2. Click Add, and then add servers one at a time by IP address, or in groups by using a subnet or domain.
    3. Click OK to close the Computer dialog box.
  10. Click OK to close the Relay Restrictions dialog box.
  11. Click OK to close the Properties dialog box.

Configure outgoing e-mail settings

Important Important:
Membership in the Farm Administrators group of the Central Administration site is required to complete this procedure.

Configure outgoing e-mail settings

  1. On the top navigation bar of the SharePoint Central Administration Web site, click Operations.
  2. On the Operations page, in the Topology and Services section, click Outgoing e-mail settings.
  3. On the Outgoing E-Mail Settings page, in the Mail Settings section, type the SMTP server name for outgoing e-mail (for example, mail.example.com) in the Outbound SMTP serverbox.
  4. In the From address box, type the e-mail friendly address as you want it to appear to e-mail recipients.
  5. In the Reply-to address box, type the e-mail address to which you want e-mail recipients to reply.
  6. In the Character set menu, select the character set that is appropriate for your language.
  7. Click OK.
    For information about how to perform this procedure using the Stsadm command-line tool, see Email: Stsadm operation (Office SharePoint Server).