Upload an Image to your SharePoint Site
It’s very easy to add a file/image to your SharePoint site via the Object Model.
1 |
System.IO.MemoryStream str = <span class="kwrd">new</span> System.IO.MemoryStream();<br /> SPSite site = <span class="kwrd">new</span> SPSite(Page.Request.Url.ToString());<br /> SPWeb web = site.OpenWeb(); <br /><br /> Bitmap.FromFile(<span class="str">"Source URL"</span>).Save(str,Imaging.ImageFormat.Gif);<br /> web.AllowUnsafeUpdates = <span class="kwrd">true</span>;<br /> <br /> web.Folders[<span class="str">"PublishingImages"</span>].Files.Add(<span class="str">"filename"</span>,str);<br /> web.Folders[<span class="str">"PublishingImages"</span>].Update();<br /> <br /> web.Close();<br /> 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 … Read More »