通过上传控件向SharePoint图片库上传图片
SPWeb spweb = SPContext.Current.Web;
SPList imageList = spweb.Lists["test1"];string photoName1 = myFile.PostedFile.FileName; //获取初始文件名
int i = photoName1.LastIndexOf("."); //取得文件名中最后一个"."的索引
string newext = photoName1.Substring(i); //获取文件扩展名
if (newext.ToLower() != ".gif" && newext.ToLower() != ".jpg" && newext.ToLower() != ".jpeg" && newext.ToLower() != ".bmp" && newext.ToLower() != ".png" )
{
Response.Write("文件格式不正确!");
Response.End();
}
DateTime now = DateTime.Now; //获取系统时间
string photoName2 = now.Millisecond.ToString() + "_" + myFile.PostedFile.ContentLength.ToString() + newext; //重新为文件命名,时间毫秒部分+文件大小+扩展名
Stream imageStream = myFile.PostedFile.InputStream;
SPFolder folder = imageList.RootFolder;
spweb.AllowUnsafeUpdates = true;
SPFile imageFile = folder.Files.Add(spweb.Url + "/test1/" + photoName2 + newext, imageStream);
imageFile.Item["说明"] = ExplainText.Text;
imageFile.Item["标题"] = TitleText.Text;
imageFile.Item.Update();