Study : There are vairuos option to try doing it, but to automate the process its better to go fir shareoint timer jobs.
Solution : Create timer jobs which starts on feature activation performing the requirement on daily basis.
- Create Timer job in a feature.
http://www.andrewconnell.com/blog/archive/2007/01/10/5704.aspx
http://www.andrewconnell.com/blog/articles/CreatingCustomSharePointTimerJobs.aspx
Only difference from the example is that you have to use SPDailySchedule
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spdailyschedule.aspx
2. Write code for perform versioning in the document library
public override void Execute (Guid contentDbId) {
try
{
string[] urlofFile = null;
string url = string.Empty;
byte[] dBytes = null;
StringBuilder verID = new StringBuilder(10);
SPFileVersionCollection vercol = null;
SPFile file = null;
//Call webapplication
SPWebApplication webApplication = this.Parent as SPWebApplication;
SPContentDatabase contentDataBase = webApplication.ContentDatabases [contentDBGuid];
//call document librarys
SPDocumentLibrary doclib1 = (SPDocumentLibrary)contentDataBase.Sites[0].RootWeb.Lists ["DocLib"];
//Archival doc library
SPDocumentLibrary doclib2 = (SPDocumentLibrary)contentDataBase.Sites[0].RootWeb.Lists["Archives"];
//get current web
SPWeb currentweb = contentDataBase.Sites[0].RootWeb;
//get filecollection.
SPFileCollection filecols = currentweb.GetFolder("/DocLib").Files;
//Call Spfolder to add items to the archive.
SPFolder doclib2Folder = currentweb.Folders["/Archives"];
foreach (SPListItem items in doclib.Items){
//file object to get the files stored in doclib
file = items.File;
if (file.Exists){
string fileurl = file.Url.ToString();
//get collection of fileversions.
vercol = filecols[fileurl].Versions;
//Add the versions to Archive documents library if not a current version.
foreach (SPFileVersion ver in vercol){
if (!ver.IsCurrentVersion){
verID = verID.Append(ver.ID);
verID = verID.Append(",");
urlofFile = ver.File.Name.Split('.');
//Add version ID of the file version for uniqueness
url = urlofFile[0].ToString() + ver.ID + "." + urlofFile[1].ToString();
//get the versions of the file.
dBytes = ver.OpenBinary();
//Add it to Archive doclibrary
currentweb.AllowUnsafeUpdates = true;
doclib2Folder.Files.Add(url, dBytes);
doclib2.Update();
currentweb.AllowUnsafeUpdates = false;
}}
//Delete the versions from the current document library
if (!string.IsNullOrEmpty(verID.ToString())){
string[] vervalues = verID.ToString().TrimEnd(',').Split(',');
int i = 0;
foreach (string s in vervalues){
currentweb.AllowUnsafeUpdates = true;
i = Convert.ToInt32(s);
vercol.GetVersionFromID(i).Delete();
currentweb.AllowUnsafeUpdates = false;
}verID.Length = 0;
}}}}
catch (Exception ex)
{//Handle Exceptions....}
}
3. Deploy the solution as a feauture to your shareoint solution and activate the feature.
Happy Coding...........