More in this section

Forums / General Discussions / Using the web services to upload documents to chosen libraries?

Using the web services to upload documents to chosen libraries?

6 posts, 0 answered
  1. G S S
    G S S avatar
    71 posts
    Registered:
    16 Mar 2008
    03 Mar 2011
    Link to this post
    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:

    http://theplaygrounds.co.uk/Sitefinity/Services/Content/DocumentLibraryService.svc//parent/{parentId}/{contentId}/?provider={providerName}&newParentId={newParentId}&version={version}&published={published}&checkOut={checkOut}&workflowOperation={workflowOperation}

    I don't see where I specifiy the document library name? Is it in parentId?


    Thanks
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    04 Mar 2011
    Link to this post
    Hi G S S,

    The ParentID is the a parameter that represents the library ID.

    Greetings,
    Ivan Dimitrov
    the Telerik team
  3. G S S
    G S S avatar
    71 posts
    Registered:
    16 Mar 2008
    04 Mar 2011
    Link to this post
    Hi,

    In the libraries I have setup. I don't see an ID, however? Where can I get this from?        

    Thanks
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    07 Mar 2011
    Link to this post
    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
  5. Basem
    Basem avatar
    131 posts
    Registered:
    22 Dec 2010
    26 Sep 2011
    Link to this post
    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?
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    27 Sep 2011
    Link to this post
    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
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
6 posts, 0 answered