Wednesday, 20 June 2012

ASCX.CS (ascx.cs)

STEP 1: Create a VisualWebPart like DepartmentImage

STEP 2: Write a coding in DepartmentImageUserControl.ascx.cs 


STEP 3:


using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data;
using Microsoft.SharePoint;
using VCSB.INTRANET.BLL;
using VCSB.INTRANET.DAL;
using System.Linq;
using Microsoft.SharePoint.Utilities;

namespace VCSB01.INTRANET.VCSBWebPart.DepartmentImage
{
    public partial class DepartmentImageUserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindDepImage();
            }
        }
        private void BindDepImage()
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {    
                      imgFileImage.ImageUrl= GetListAttachments().ToString();
                      
            });
         
        }

        private object GetListAttachments()
        {
            string URL = null;
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                SPSite spsite= SPContext.Current.Site;
                SPWeb spWeb = spsite.OpenWeb();
                SPList spList = spWeb.Lists["DepartmentImage"];
                SPListItemCollection spListItems = spList.Items;             
                foreach (SPListItem item in spListItems)
                {
                    SPAttachmentCollection collAttachments = item.Attachments;
                        foreach (var attachment in collAttachments)
                        {
                            URL = (SPEncode.HtmlEncode(item.Attachments.UrlPrefix + attachment.ToString()));
                        }
                }

            });
            if (URL != null)
            {
                return URL;
            }
            else
            {

                return URL = @"~\_Layouts\Images\VCSB\photo_not_avl.png";
            }
        }

    }
}
 

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 ; ...