Using the web services to upload documents to chosen libraries?
Hi,
I am looking to upload documents to my Sitefinity site, using the web services provided out-of-the-box. In particular, documentlibrary/document. These two web services seem very similar.
In specific, I have a few document libraries I setup. Is it possible to selectively choose which library to upload to? Looking at this url:
theplaygrounds.co.uk/.../
I don't see where I specifiy the document library name? Is it in parentId?
Thanks
Hi G S S,
The ParentID is the a parameter that represents the library ID.
Greetings,
Ivan Dimitrov
the Telerik team
Hi,
In the libraries I have setup. I don't see an ID, however? Where can I get this from?
Thanks
Hi G S S,
You can use the fluent API to get the IDs.
App.WorkWith().DocumentLibraries().ForEach(lib =>
var id = lib.Id;
);
All the best,
Ivan Dimitrov
the Telerik team
I do not see where I can define streams or bytes for the actual file. Is it possible to upload a file remotely to Sitefinity from another system via web service? I would image it would involve sending a blob or posting a file remotely to Sitefinity?
Hi Basem,
The LibrariesManager has a method
virtual void Upload(MediaContent content, Stream source, string extension)
where you can pass the stream
var album = this.CreateLibrary<DocumentLibrary>(albumTitle);
albumId = album.Id;
var manager = LibrariesManager.GetManager();
var document = manager.CreateDocument();
document.Parent = album;
document.Title = title;
document.UrlName = title.ToLower().Replace(' ', '-');
using (var stream = ImageStream())
manager.Upload(document, stream, ".jpeg");
manager.Publish(document);
manager.SaveChanges();
private Stream ImageStream()
System.Drawing.Image imgThumb = new Bitmap(100, 100, PixelFormat.Format24bppRgb);
MemoryStream ms = new MemoryStream();
System.Drawing.Bitmap b = new System.Drawing.Bitmap(imgThumb);
Graphics objGraphics = Graphics.FromImage(b);
Font objFont = new Font("Arial", 40, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel);
objGraphics = Graphics.FromImage(b);
objGraphics.Clear(Color.White);
objGraphics.SmoothingMode = SmoothingMode.AntiAlias;
objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
objGraphics.DrawString("sampleImage", objFont, new SolidBrush(Color.FromArgb(000, 122, 102)), 0, 0);
b.Save(ms, ImageFormat.Jpeg);
return ms;
Greetings,
Ivan Dimitrov
the Telerik team