Internet Explorer 9 Beta is available for download

IE 9 beta is available for download. Some of the top features include

  • Hardware accelerated graphics and text
  • Clean browser interface
  • Pinnable sites
  • Jump Lists
  • New javascript Engine – Chakra
  • HTML5 support
  • Developer Tools

So why wait, grab a copy and start exploring.You can get it here
http://www.beautyoftheweb.com

How to check for attachments in ItemAdding() event

Item adding being a synchronous event nor the list item and attachments are committed in database. Hence if you need to get the attachments in ItemAdding() event then you could do so by ASP.NET request object

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

namespace MyProject.Features
{
    public class MyEventReceiver : SPItemEventReceiver
    {
        HttpContext currentContext;

        public MyEventReceiver()
        {
            currentContext = HttpContext.Current;
        }
       
        public override void ItemAdding(SPItemEventProperties properties)
        {            
  if (currentContext != null)
        {
          if (currentContext.Request.Files.Count > 0)
          {

            // there are attachments

          }
   else
   {

            // there are no attachments

   }
        }                           
        }
     }
}

Create listview webpart to show items inside folders

When you navigate inside a folder inside a document library you will notice that the URL changes. SharePoint makes use of URL Querystring to display data inside folders.

Assume you have document library as “Shared Documents” and you create a folder called as “mydocument” inside it. when you navigate inside the folder the url in your browser should look something like this

http://{yoursite}/Shared%20Documents/Forms/AllItems.aspx?RootFolder=/Shared%20Documents/mydocument&FolderCTID=&View={A4A4A2E6-AE49-4173-B738-A14A4A1A49A0}

As you may see that the SharePoint OOTB list view webpart uses these three parameters (RootFolder,FolderCTID,View) to render the folder contents to you

RootFolder – Root Folder URL
FolderCTID – Folder Content Type ID (optional)
View – Specified View Guid for the Document library

So you need to create a custom list view web part and then set the following three properties to show data inside a specific folder

But there is a catch here. You can set the View for a listview web part but not the “RootFolder” and “FolderCTID” as they are managed internally by sharepoint.Here we will use refelection to set these values and achieve desired results

Code Sample

protected override void CreateChildControls()
    {
      base.CreateChildControls();
      try
      {
        SPSite site = new SPSite("http://{yoursite}");
        SPWeb web = site.OpenWeb();
        SPList list = web.Lists["Shared Documents"];

        // Instantiate the web part
        ListViewWebPart lvwp = new ListViewWebPart();
        lvwp.ListName = list.ID.ToString("B").ToUpper();
        lvwp.ViewGuid = list.Views["SomeView"].ID.ToString("B").ToUpper();
              
        //Get the rootfolder url here and content type id of folder e.g. "0x012000C5E1253B0EF534479884B846FA62FCFC"
      
       SPFolder folder = web.GetFolder("/Shared Documents/mydocument");

       SPContentTypeId folderctid = folder.Item.ContentType.Id;

        //set the folder url
        SetPrivateFieldValue(lwwp,"rootFolder",folder.Url);
        
       // set the folder content type id ----- Note this is optional and can be skipped 🙂 
       SetPrivateFieldValue(lwwp,"folderCtId",folderctid.ToString());

        lvwp.GetDesignTimeHtml();
        this.Controls.Add(lvwp);
      }
      catch (Exception ex)
      {
        Label lbl = new Label();
        lbl.Text = "Error occured: ";
        lbl.Text += ex.Message;
        this.Controls.Add(lbl);
      }
    }

private static void SetPrivateFieldValue(object obj, string fieldName,string val)
{
  FieldInfo fi = obj.GetType().GetField(fieldName,System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
  fi.SetValue(obj, val);
}