Count total no. of downloads of a file from document library - liferay

I'm trying to make a portlet which shows most downloaded files from document library.
Thanks in advance.

Take a look at com.liferay.portlet.documentlibrary.service.DLFileEntryServiceUtil
Specifically
com.liferay.portlet.documentlibrary.service.DLFileEntryServiceUtil.getFileEntry(long groupId, long folderId, java.lang.String name)
You will get DLFileEntry so
DLFileEntry dlfe = com.liferay.portlet.documentlibrary.service.DLFileEntryServiceUtil.getFileEntry(my-group-id, folder-id, name);
dlfe.getReadCount();
will get you what you want.

Related

Netsuite logger string is too long to show up in details field

When I log a whole Purchase or sales order record object using JSON.stringifyy(SOobject);,the logger don't show the whole object, What could I do to see entire object. The log level used is Log.debug({})
As per NetSuite's documentation, you cannot log more than 3999 characters in one log - see excerpt from SuiteAnswers "log.debug(options)" page below:
For a temporary quick and easy solution to overcome this limitation in order to troubleshoot some specific part of your script, you can call email.send() and include the details in the email body.
Similar to what Krypton suggested, typically I will write my long JSON or other data directly to an output text log file in the file cabinet. This I find is more reliable because sandbox will not send out emails unless specifically configured to do so.
Our approach for long string is that we separate the long log string into several parts and print each one.
function logger(str) {
str.match(/.{1,3000}/g).forEach(function(smallString, idx) {
log.debug('part' + idx, smallString);
});
}
var longStr = 'xxxx.....xxxxxx'; // This is your long string
logger(longStr);
However, I think sending mail is a better way in this case :)

Getting PDF_VALIDATION_FAILED exception when trying to create envelopne in DocuSign sample recipe code

I am trying to run the code available on GitHub.
Issue is when I am trying to create an envelope I am getting an exception saying "PDF_VALIDATION_FAILED".
Can anyone help me out with this issue?
Really you should be creating a new issue to log the new error you are getting, or modify your original post. In any case the issue is most likely due to the file extension, the default is pdf so if you want to send a different format document you can do the following:
// Add a document to the envelope
Document doc = new Document();
doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes);
doc.Name = Path.GetFileName("/PATH/TO/DOC/TEST.DOCX");
doc.DocumentId = "1";
doc.FileExtension = "docx";
I managed to get a fix for this one. Apparently the file I was uploading was a corrupt file. However, not I am getting a different error 'UNABLE_TO_LOAD_DOCUMENT' when I try to upload a file in any format other than pdf.
Can anyone help me with this query? Also, what all file formats does DocuSign support?
Also, one of the previous libraries 'DocuSign.Integrations.Client' seem to work fine with word document uploads. Should they be used instead of 'DocuSign.eSign.Api', 'DocuSign.eSign.Client' and 'DocuSign.eSign.Model'?
This is in response to the second error you mentioned:
I think you are missing assigning the FileExtension to the required format
something like : doc.FileExtension = "docx"
Once you do that, you will get rid of UNABLE_TO_LOAD_DOCUMENT error and the document can be sent successfully.

File upload with metadata using SharePoint Web Services

I trying to upload a file with metadata using SharePoint Web Services. The first approach I took is to use the WebRequest/WebResponse objects and then update the metadata using the Lists.asmx - UpdateListItems method. This works just fine but it creates two versions of the file. The second approach I took was to use the Copy.asmx web service and use the CopyIntoItems method which copies the file data along with the metadata. This works fine and creates v 1.0 but when I try to upload the same file with some changes in the metadata (using the Copy.asmx) it does not do update anything. Does anybody came across the same issue or has some other ideas to implement the required functionality.
Thanks,
Kiran
This might be a bit of topic (sorry) but I'd like to advice you to a real timesaving shortcut when working with SharePoint remotely, http://www.bendsoft.com/net-sharepoint-connector/
It enables you to work with SharePoint lists and document libraries with SQL and stored procedures.
Uploading a file as a byte array
...
string sql = "CALL UPLOAD('Shared Documents', 'Images/Logos/mylogo.png', #doc)";
byte[] data = System.IO.File.ReadAllBytes("C:\\mylogo.png");
SharePointCommand cmd = new SharePointCommand(sql, myOpenConnection);
cmd.Parameters.Add("#doc", data);
cmd.ExecuteNonQuery();
...
Upload stream input
using (fs == System.IO.File.OpenRead("c:\\150Mb.bin")) {
string sql = "CALL UPLOAD('Shared Documents', '150Mb.bin', #doc)";
SharePointCommand cmd = new SharePointCommand(sql, myOpenConnection);
cmd.Parameters.Add("#doc", fs);
cmd.ExecuteNonQuery();
}
There are quite a few methods to simplify remote document management
UPLOAD(lisname, filename, data)
DOWNLOAD(listname, filename)
MOVE(listname1, filename1, listname2, filename2)
COPY(listname1, filename1, listname2, filename2)
RENAME(listname, filename1, filename2)
DELETE(listname, filename)
CREATEFOLDER(listname, foldername)
CHECKOUT(list, file, offline, lastmodified)
CHECKIN(list, file, comment, type)
UNDOCHECKOUT(list, file)
Cheers

Check in and Check out in SPFile object

I use the following piece of code to check out and then check in a file. I use IronPython.(Say spfile is the SPFile object)
spfile.CheckOut()
spfile.CheckIn("Done by the script")
spfile.Update()
spfile.CheckOut()
spfile.CheckIn("Done by the script-Second time")
The file is checked in for the first time. But the second time, it throws an exception stating that, the file has been modified at a particular time by SHAREPOINT\system. I find this obscure as I have updated the file already. Any help would be appreciated
Basically its a transcational issue. You need to get a new reference to the SPfile object in order to refresh the underlying version information and last transaction.
spfile.CheckOut()
spfile.CheckIn("Done by the script")
spfile.Update()
spfile = SPlistItem.File;
spfile.CheckOut()
spfile.CheckIn("Done by the script-Second time")

SharePoint 2007: How to check if a folder exists in a list using web services?

Using SharePoint 2007 webservices or even Webdav, how can I check if a folder exists in a list (not document library) in SharePoint.
I would also like to check for subfolders...
Anyone have any idea on how this is done? I've asked Microsoft, and their official stance is that Microsoft provide no documentation on this. so any help will be most welcome...
Thanks in advance...
I have this code that creates a folder, but not sure how to modify it to check if the folder exists, also not even sure if this will work with sub folders...
private void CreateFolderUsingWebService(string listName, string folderName)
{
//Check Databox Folder Exists
//string folderAddress = siteAddress + #"/lists/" + listAddress + #"/" + folderName;
//wsDws.CreateFolder(folderAddress);
var doc = new XmlDocument();
XmlElement batch = doc.CreateElement("Batch");
string item = "<Method ID=\"1\" Cmd=\"New\">" +
"<Field Name=\"ID\">New</Field>" +
"<Field Name=\"FSObjType\">1</Field>" +
"<Field Name=\"BaseName\">" + folderName + "</Field></Method>";
batch.SetAttribute("ListVersion", "1");
//batch.SetAttribute("ViewName", "{GUID of View, including braces}");
batch.InnerXml = item;
wsLists.UpdateListItems(listName, batch);
}
Ok - this info might help the next SharePoint developer:
The function above works, and will even create a directory structure. BUT you need to pass the list name, not the list URL, this means if you localize your code, you need to pass the localized list name to the function.
I didn't bother adding a check for ifExists, because it seems to NOT create duplicates or fail if the directory already exists. I know this isn't a great solution, but I just don't have 2-3 weeks to research how to do it properly, so if you have any suggestions, comments are welcome.
Lastly any Microsoft representation reading this - might want to consider why there isn't any really good documentation on this with how to's from MS? Mmmmm
I went as far as downloading the MOSS Web Services SDK, and it contains 1 very vague example of how to use 1 function in the Lists web service, this simply is not enough information for those of us trying to put together robust solutions in MOSS. We need way more documentation please...

Resources