c# - programmatically adding files to the Kentico Media Library -


using cmsdesk , click on tools tab, media library can add files inbuilt kentico media library. there way using api?

you can using kentico api. quite rich documentation , samples out there bit lacking.

following sample method (actually used web service method have both remote , local pages use it) , sample method calls (say 'edit' web page).

filelogo - > protected system.web.ui.webcontrols.fileupload filelogo;

        [webmethod]     public bool import(int libraryid, string foldername, string filename, byte[] bytes)     {         siteinfo siteinfo = siteinfoprovider.getcurrentsite();         medialibraryinfo libraryinfo = medialibraryinfoprovider.getmedialibraryinfo(libraryid);          filename = filename.replace(" ", "-").replace("&", "-").replace("'", "-").replace("+", "-").replace("=", "-").replace("[", "-").replace("]", "-").replace("#", "-").replace("%", "-").replace("\\", "-").replace("/", "-").replace(":", "-").replace("*", "-").replace("?", "-").replace("\"", "-").replace("<", "-").replace(">", "-").replace("|", "-");          bool bretvalue = false;          string filepath = server.mappath(string.format("/{0}/media/{1}/{2}/{3}", siteinfo.sitename, libraryinfo.libraryfolder, foldername, filename));         file.writeallbytes(filepath, bytes);         if (file.exists(filepath))         {             string path = medialibraryhelper.ensurepath(filepath);             mediafileinfo fileinfo = new mediafileinfo(filepath, libraryinfo.libraryid, foldername);             fileinfo.filesiteid = siteinfo.siteid;             mediafileinfoprovider.importmediafileinfo(fileinfo);             bretvalue = true;         }          return bretvalue;     }              string filepath = "~/sitename/media/site_medialib/logos/";         string filename = string.empty  ;          if (filelogo.filename.length > 0)         {             var ext = filelogo.filename.substring(filelogo.filename.lastindexof('.') + 1).tolower();              filename = entrytitle + "." + ext;               medialibrary il = new medialibrary();             il.import(3, "foldername", filename, filelogo.filebytes);         } 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -