Upload an Image to your SharePoint Site
24. April 2007 05:49

It's very easy to add a file/image to your SharePoint site via the Object Model.

 

            System.IO.MemoryStream str = new System.IO.MemoryStream();
SPSite site = new SPSite(Page.Request.Url.ToString());
SPWeb web = site.OpenWeb();

Bitmap.FromFile("Source URL").Save(str,Imaging.ImageFormat.Gif);
web.AllowUnsafeUpdates = true;

web.Folders["PublishingImages"].Files.Add("filename",str);
web.Folders["PublishingImages"].Update();

web.Close();
site.Close();

I was also interested in adding an image to an image library via the OM, but haven't had a chance to play around with it yet, let me know if you've done this already.

Exception: Object reference not set to an instance of an object.
Tags: Comments (0) | Permalink

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading