1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Uploading images from front end Winforms

Uploading images from front end Winforms

4 posts, 0 answered
  1. Tim
    Tim avatar
    7 posts
    Registered:
    13 Aug 2009
    01 Oct 2009
    Link to this post
    I have a front end winforms program that includes a database of products as well as corresponding images for these products.

    I need to accomplish 2 tasks.

    1. Synchronize the database with the website database.
    2. Programatically upload the corresponding images that are associated with this database.

    I have already completed step one through a series of web services that change alter and add to my database of product information.

    However, I am not sure of the best approach for step 2 (to synchronize the local folder of image files on our server with the remote website). Is there any support through Sitefinity to programatically upload these files from the local winform program, should I use basic ftp procedures or maybe a web service to upload?

    -Tim
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    02 Oct 2009
    Link to this post
    Hello Tim,

    Thank you for using our services.

    You can try and use the Telerik.Libraries API (API for Images and Documents module), and programmaticaly fetch images to a Image library in Sitefinity. You can check our on-line Developer Manual for examples on this. Please check the Library Manager  examples to see how to Create, Delete, Modify, Find libraries programmaticaly. Then you should look at how to manage files with Library Manager, and how to upload images to image library.

    This should help you achieve the second step - to programmatically insert images into your Sitefinity web site's database.

    If you have more questions, please feel free to post in the forums or contact Telerik Support.

    Best wishes,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Tim
    Tim avatar
    7 posts
    Registered:
    13 Aug 2009
    02 Oct 2009
    Link to this post
    This is basically what I ended up doing.

    Thanks for the direction.


         
       [WebMethod]  
            public bool UploadImage(byte[] ImgIn,string fileName,string libraryName)  
            {  
                if(!fileName.EndsWith(".jpg",StringComparison.OrdinalIgnoreCase)) return false;  
                fileName.Remove(fileName.Length-4);  
     
                System.IO.MemoryStream ms =  
                new System.IO.MemoryStream(ImgIn);  
     
     
                // create new instance of LibraryManager  
                Telerik.Libraries.LibraryManager libraryManager = new Telerik.Libraries.LibraryManager();  
                // get library by specified Name  
                Telerik.Libraries.ILibrary parentLibrary = libraryManager.GetLibrary(libraryName);  
                if (parentLibrary == null)  
                {  
                    parentLibrary = libraryManager.CreateLibrary();  
                    parentLibrary.Name = libraryName;  
                    parentLibrary.TypeName = "Image";  
                    libraryManager.SaveLibrary(parentLibrary);  
                }  
                
                // create an image content item  
                Telerik.Cms.Engine.IContent testContent = libraryManager.CreateContent("image/jpeg");  
                // specify parent library the image will belong to  
                testContent.ParentID = parentLibrary.ID;  
     
                Telerik.Cms.Engine.IContent content = null;  
                // upload the file  
                try 
                {  
                    content = libraryManager.UploadFile(ImgIn,  
                    fileName,  
                    "jpg",  
                    "image/jpeg",  
                    ImgIn.Length,  
                    parentLibrary);  
                }  
                catch (ArgumentException ex)  
                {  
                      
                   //handle this
                }  
                // save the image as a content of the file  
                testContent.Content = ImgIn;  
     
                return true;  
            } 
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    05 Oct 2009
    Link to this post
    Hi Tim,

    Thank you for the feedback.

    I am happy that I was able to assist you in a way. It is great that you are sharing your approach with the rest of the community, and really appreciate that.

    If you have more questions regarding Sitefinity, please feel free to contact us.

    All the best,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
4 posts, 0 answered