ASPX templates
Version 5.x > ASPX templates > Allowing for download of a particular version of a document View modes: 
User avatar
Member
Member
chris.percival-oakwood-dc - 5/10/2010 11:06:59 AM
   
Allowing for download of a particular version of a document
I am trying to create a file repository, one of my requirements is that previous versions of a document (attachment) can be downloaded. I am able to get the previous versions with GetDocumentHistory.VersionManager and can get the related attachment info with the AttachmentManager, but am unable to find an easy way of downloading the file. Will I have to write my own function to serve the attachment history data to the client?

User avatar
Member
Member
chris.percival-oakwood-dc - 5/11/2010 5:29:50 AM
   
RE:Allowing for download of a particular version of a document
I have thrown the following code together:


protected string GetAttachmentUrl(int versionHistoryID)
{
DataSet va = vm.GetVersionAttachments(versionHistoryID, false);
DataRow row = va.Tables[0].Rows[0];

AttachmentInfo ai = am.GetAttachmentInfo((Guid)row["AttachmentGUID"], CMSContext.CurrentSite.SiteName);

return DocumentHelper.GetAttachmentUrl(ai, versionHistoryID);
}


Which generates the following promising looking url:
http://localhost:50468/KenticoCMS.VersionTest/CMSPages/GetFile.aspx?guid=629ca50e-4fa4-41c4-aecb-2baeaa47d05b&versionhistoryid=1


However GetFile.aspx doesn't seem to be able to deal with this attachment... :(

User avatar
Kentico Developer
Kentico Developer
kentico_ondrejv - 5/11/2010 9:13:49 AM
   
RE:Allowing for download of a particular version of a document
Hello,

GetFile script should handle this. Please check in your database, whether the GUID which is being generated is correct (if belongs to correct attachment). You can check that in CMS_AttachmentHistory table.

Basically, what do you receive when you click the link, or use this URL?

Best regards
Ondrej Vasil

User avatar
Member
Member
chris.percival-oakwood-dc - 5/13/2010 8:40:14 AM
   
RE:Allowing for download of a particular version of a document
Thanks for your help via email!

What was happening was that I was logged out at the time. There seems to be a restriction retrieving past versions of files for an un-authenticated user:

GetFile.aspx line 1139:

// Check the permissions for the document
if ((CurrentUser.IsAuthorizedPerDocument(node, NodePermissionsEnum.Read) == AuthorizationResultEnum.Allowed) || (node.NodeOwner == CurrentUser.UserID))

CurrentUser.IsAuthorizedPerDocument was not returning AuthorizationResultEnum.Allowed and so was getting nothing returned to be when I requested the url. Requesting the original document with the url returned by GetDocumentUrl() in the my transformation works logged in or out. This isn’t a major issue for our application as all content will be restricted to authorised users anyway.