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

Forums / Developing with Sitefinity / Document Library : Synchonised with a network folder

Document Library : Synchonised with a network folder

4 posts, 0 answered
  1. Kevin
    Kevin avatar
    3 posts
    Registered:
    18 Feb 2008
    20 Apr 2009
    Link to this post
    Hi all,

    Is it possible to have a Document Library automatically synchronised with a network folder?  When a new file gets added to the network folder, it should automatically appear in the document library soon after.

    I had a poke around the sitefinity api and believe that it would be possible to write some code to do it, just wondering if there is something out of the box, or maybe someone has already written something to do this.

    Cheers,

    Kevin
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    20 Apr 2009
    Link to this post
    Hello Kevin,

    There is no option for your requirement out of the box. When a file is uploaded through Sitefinity interface, it goes to the database. My suggestion is following - create a simple logic that saves a file to the File system when an item is uploaded through Images and Documents.

    Example:

    using System; 
    using System.Collections.Generic; 
    using System.Web; 
    using System.Web.UI; 
    using Telerik.Web.UI; 
     
    /// <summary> 
    /// Summary description for ItemUploader 
    /// </summary> 
    public partial class Sitefinity_Admin_ControlTemplates_Libraries_ItemUploader : System.Web.UI.UserControl 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            Control control = this.FindControl("filesUpload"); 
            RadUpload upload = control as RadUpload; 
            foreach (UploadedFile file in upload.UploadedFiles) 
            { 
                file.SaveAs("c:\\uploaded files\\" + file.GetName(), true); 
            } 
     
        } 

    The other way - when an item is uploaded to dir, then create this item to Images and Documents library require using Timer class, you should set checking your directory on a certain time of period. Then, iterate through all items and compare them with the items in your library. If a new item us uploaded, then create IContent object.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Kevin
    Kevin avatar
    3 posts
    Registered:
    18 Feb 2008
    21 Apr 2009
    Link to this post
    Thanks Ivan,

    I was thinking more of the "other way" you mentioned.

    No worries, I start down that road.  Thanks for your help.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    21 Apr 2009
    Link to this post
    Hello Kevin,

    Here is a sample code that could help you.

     // here we are saving an old list of the items before 
            // our timer to run 
            // just fore demonstration. 
            List<string> oldFilesList = new List<string>(); 
     
            // this is our directory where we store files 
            string[] files = Directory.GetFiles("C:\\"".jpeg"); 
     
            // here we are creating a list of new  files 
            List<string> newFileList = new List<string>(); 
            foreach (string file in files) 
            { 
                newFileList.Add(file); 
            } 
     
            // check whether the new list contains files  
            // from our old list - if the file is not there 
            //anymore we delete the file using ContentManager 
            foreach (string oldFile in oldFilesList) 
            { 
                if (!newFileList.Contains(oldFile)) 
                { 
                    // delete 
                } 
     
            } 
     
            // if the file does not exist we are 
            // we are adding it using ContentManager 
            foreach (string newFile in newFileList) 
            { 
                if (!oldFilesList.Contains(newFile)) 
                { 
                    // add new file 
                } 
     
            } 

    You can also save some hash data between the timer run/ or your requests, thus you will decrease the performance. I hope this helps.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
4 posts, 0 answered