使用Picture Library可以方便的处理图片,例如生成缩略图,预览图等等。
首先创建一个Picture Library:
private const string MyPictureLibraryTitle = "MyPictureLibrary";
public void EnsureMyPictureLibrary(SPWeb web)
{
if (web.Lists.TryGetList(MyPictureLibraryTitle) == null)
{
SPSecurity.RunWithElevatedPrivileges(() =>
{
Guid pictureLibraryGuid = web.Lists.Add(MyPictureLibraryTitle, "Picture Library to store images", SPListTemplateType.PictureLibrary);
web.AllowUnsafeUpdates = true;
web.Update();
web.AllowUnsafeUpdates = false;
});
}
}
创建成功之后,向MyPictureLibrary中上传一张图片,SharePoint会根据上传的图片生成对应的缩略图和预览图,然后将这两个图片的url保存在item的Xml属性中: