Month: August 2012

WCF with sharepoint 2010 service

Try below code, it works perfectly fine:-

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Linq;
using Microsoft.SharePoint.Linq;
using WCFService.ListWCFService;
namespace WCFService.WP_WCFService
{
    public partial class WP_WCFServiceUserControl : UserControl
    {
       
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }
        protected override void OnPreRender(EventArgs e)
        {
            try
            {
                System.Uri uri = new Uri(“http://localhost:16178/_vti_bin/ListData.svc“);
               SrgDataContext dc = new SrgDataContext(uri);
               dc.Credentials = System.Net.CredentialCache.DefaultCredentials;
                    var query = from dev in dc.Announcements
                                select new
                                {
                                    Title = dev.Title,
                                    Body = dev.Body,
                                    ExpiryDate = dev.Expires,
                                    Path = dev.Path
                                };
                    gridAnnouncementList.DataSource = query;
                    gridAnnouncementList.DataBind();
             
                //dc.Dispose();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
           

                try
                {
                    System.Uri uri = new Uri(“http://localhost:16178/_vti_bin/ListData.svc“);
                    WCFService.ListWCFService.SrgDataContext dc = new WCFService.ListWCFService.SrgDataContext(uri);
                    dc.Credentials = System.Net.CredentialCache.DefaultCredentials;
                   
                   dc.AddToAnnouncements(
                            new AnnouncementsItem
                            {
                                Title = txtTitle.Text,
                                Body = txtBody.Text
                            });

                    //dc.Announcements.InsertOnSubmit(newAnnouncement);
                    //dc.c();
                   dc.SaveChanges();
                   // dc.Dispose();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
          
      
        }
    }
}

Using Sharepoint rich text box in Web Part

Just add below line in sharepoint project visual web part ascx file:-
<SharePoint:InputFormTextBox runat=”server” ID=”txtBody” TextMode=”MultiLine” ValidationGroup=”CreateCase” Rows=”8″ Columns=”40″ RichText=”true” RichTextMode=”FullHtml” AllowHyperlink=”true” />