Lifeary - Creating folders and sub folders under Web Content using portlet - liferay

I am working on reading excel data in portlet and putting it under Web Content and sorting them into different folders and subfolders.
All I found is creating files and folders under the Documents and Media library but not under the Web Content
https://help.liferay.com/hc/en-us/articles/360029045451-Creating-Files-Folders-and-Shortcuts
https://help.liferay.com/hc/en-us/articles/360028725672-Creating-Folders
Follow these steps to create a folder with the DLAppService method addFolder:
Get a reference to DLAppService:
#Reference
private DLAppService _dlAppService;
Get the data needed to populate the addFolder method’s arguments. Since it’s common to create a folder with data submitted by the end user, you can extract the data from the request. This example does so via javax.portlet.ActionRequest and ParamUtil:
long repositoryId = ParamUtil.getLong(actionRequest, "repositoryId");
long parentFolderId = ParamUtil.getLong(actionRequest, "parentFolderId");
String name = ParamUtil.getString(actionRequest, "name");
String description = ParamUtil.getString(actionRequest, "description");
ServiceContext serviceContext = ServiceContextFactory.getInstance(
DLFolder.class.getName(), actionRequest);
Call the service reference’s addFolder method with the data from the previous step:
Folder folder = _dlAppService.addFolder(
repositoryId, parentFolderId, name, description,
serviceContext);
Please let me know or guide me on how to solve this problem.
Thanks in advance.

In the Document Library, you can upload and store documents.
Under Web Content, you can create and store web content articles.
You sound like you want to store documents (e.g. excel files) under Web Content, and that's not what those folders are being built for. Note that this is not a file system, but those are distinct ways to organize the different types of content.
So, the way to solve this problem is to go back to the requirements, and find a working technical solution for the underlying business problem.
Any folder you create through an API with the DL prefix will appear under the Document Library. Any folder you create through an API starting with a Journal prefix will appear under Web Content. There simply is no overlap.

Related

The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator while renaming site column

I am getting
"The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator"
while renaming site column in SharePoint online using CSOM. I have faced this issue in the past while fetching items from the large list but this is a different scenario, here I am just trying to rename the site column.
This issue is caused by the Item Count exceed the list view threshold limitation. And No matter retrieve item or rename site column with CSOM, it will throw such exception.
For SharePoint Online, to come across this limitation, here are some way:
Use indexed column.
Reduce the list item and create multiple views which make sure the item count is less than list view threshold.
More information please refer:
Office 365: How SharePoint Online handles List View Threshold
I faced the same issue accessing the folders from Sharepoint online. One of my subfolder under Sites rootfolder had 6000+ subfolders, resulting to threshold limit error. So instead, I user alternative way to access only specific folder that I need using GetFolderByServerRelativeUrl function. Steps were...
Get Online Context
Get List of items. It will also provide the root folder.
Using GetFolderByServerRelativeUrl, get only specific folder within this root folder. Below code may help further.
private Folder GetSubFolder(Web web, Folder rootFolder, string subFolderName)
{
Folder subFolder = null;
try
{
//If folder exists, get the folder form Sharepoint Cloud
subFolder = web.GetFolderByServerRelativeUrl(rootFolder.ServerRelativeUrl + "/" +subFolderName);
web.Context.Load(subFolder);
web.Context.ExecuteQuery();
}
catch (ServerException ex)
{
subFolder = null;
}
return subFolder;
}
}

Default folders on SharePoint Document Set

I'm trying to achieve a project documentation solution on SharePoint 2013 using a custom Document Set Content Type. Each new project Document Set would hold four types of documents.
My initial thought was to use folders for each type to allow easy drag and drop behavior for adding documents. The problem is, by default, folders can be created only by adding default documents to a Document Set Content Type. I wish to create the folders upon the creation of new instance of this Document Set but not add any documents inside these folders.
This is what I have tried so far:
Using workflow to delete default documents inside folders that were created in the new Document Set.
Custom folder Content Types.
The reason for use of folders is to avoid metadata tagging when uploading documents.
I'm quite restricted with the tools that I can use so the most basic level solutions would be appreciated.
To be more clear, I would hope to have a Document Set Content Type which holds four folders. Document Set would act as a holder for all documentation relevant for a single project and folders inside would group the documentation into groups. Each new project will generate documents in its lifespan and these documents should be grouped into categories, say marketing, finance, production and HR. So when I have a new project, I can create a new instance of custom Document Set with pre created, named, empty folders inside.
There's two ways you can achieve this I think. First would be to set-up your document set to have an empty document deployed to all of the folders you'd like to create. Simply add "Default Content" to your document set and there specify the correct folders. Unfortunately there's no way to create empty folders, so you'll need to put a dummy document in each folder which the user can then delete or override.
Second would require some coding. By attaching a remote event receiver to the library, you could trigger some custom code which would create the folder structure inside of the document set once created. This would allow you to create the folder structure without the need for dummy documents; so it's a bit more work which requires a developer, but the end result is also better.
The second solution you might also be able to pull off in a workflow (or Microsoft Flow) which then uses the API's to create the folders, but that's most likely less clean and more hassle to get working.
Create a custom content type called "Folder Creator". Use that content type to create the subfolders. Then have the "Folder Creator" content type auto delete using SharePoint Information Management Policies. Be sure to set your "Expiration Policy" job to run at least once a day.

Bulk file upload creates multiple versions of all files except last file

I have an interesting (well to me anyways) problem here. I am doing a code based mass upload of documents into a SharePoint library with a twist. The twist is that the file's last modified date needs to be maintained in the item properties after the upload.
The file details are determined from a csv file that contains the path and the metatdata that needs to be attached to the library items as the library is based on a custom content type with metadata fields.
The problem I am having is that the modified date is only being maintained with the last file uploaded. All other files indicate the upload time. I did a little more digging and turned on version control. It turns out that files that I have uploaded are being modified multiple times as they have multiple minor versions applied to them, while the final file being uploaded has only one. For example. I am uploading 6 files to test out the process. The last file that is uploaded is sitting at version .1, the other files range from version .6 to .8 to .12. All files you can see had the correct modified date at the initial setup upon upload, but immediately a change occurred that modified the date and incremented the new modified date.
Version History:
I have tried an date using the following methods:
spFile.Item.UpdateOverwriteVersion()
item.Update() (when accessing items as a list and not from a file object
spFile.Item.SystemUpdate(false)
None of these updates seem to do what I wish.
Try
Using site As SPSite = New SPSite(siteURL)
Using Web As SPWeb = site.OpenWeb()
Dim itemList As SPList = Web.Lists("DM Import Test")
For Each item As SPListItem In itemList.Items
If item.Name = importFile.fileName Then
item(SPBuiltInFieldId.Modified) = importFile.modifiedDate
item.Update()
End If
Next
End Using
End Using
importFile is just a custom object with the properties I need.
Please let me know if you have come across this and if you happen to have a resolution.
I also tried building the entry with:
spFile = uploadFolder.Files.Add(Path.GetFileName(importFile.FullPath), fileStream, createdBy, modifiedBy, created, modified)
Where the uploadFolder was an folder object of the libary.
Thank you.

Access List items in hidden "Forms" folder using Lists.GetListItems

Is it possible to access the list items in the (hidden) "Forms" subfolder of a document library using the Lists.GetListItems web service method? I need to set the content type of uploaded document templates using Lists.UpdateListItems, otherwise, document created from these templates will have the 'Document' content type and not the content type the template had been assigned to.
Lists.UpdateListItems works in subfolders of the "Forms"' folder, but I need the ows_UniqueId of the list item that represents the uploaded file, and I can only get it using List.GetListItems.
Is there maybe another method of uploading files to SharePoint document libraries, in which you can set the content type?
List.GetListItems expects you to pass it a view, if you don't it uses the defaults view. So what you need to do is create a seperate view which lists all items, and make this view list flat (not listing by subfolder).
Then query against this view.
Does this suck? Yes. Does SharePoint suck? I'll let you answer that question. I didn't write sharepoint, just telling you the way it is.
I don't understand the relationship between the content type of an uploaded document in a document library and the elements in the Forms subfolder.
What I'd try:
- Use Copy Web Service, method CopyIntoItems to upload the file, setting some properties, including the content type.
- Use Lists.GetListItems, with a CAM query specifying the file name and asking for ows_UniqueID property

Placing Share Documents subfolder as a webpart in SharePoint

I want to place a Webpart on a page that holds a subfolder of the Document Library in SharePoint, but somehow, the only thing I get is the root folder of the document library.
Is there a Webpart that fills this need?
Here is how to do it in Sharepoint 2010 with only Javascript, no SharePoint Designer necessary.
create a document library web part on your web part page
change the view to show all items without folders and set the item limit to a sufficiently large number so that there are no batches
add Content Editor web part below document library web part
Add the following javascript and change the the first variable to meet your needs
Note: If you have more than one Document Library web part, you will need to add to this code.
<script type="text/javascript" language="javascript">
//change this to meet your needs
var patt = /FOLDER%20TO%20SEARCH/gi;
var x = document.getElementsByTagName("TD"); // find all of the TDs
var i=0;
for (i=0;i<x.length;i++)
{
if (x[i].className =="ms-vb-title") //find the TDs styled for documents
{
var y = x[i].getElementsByTagName("A"); //this gets the URL linked to the name field
//conveniently the URL is the first variable in the array. YMMV.
var title = y[0];
//search for pattern
var result = patt.test(title);
//If the pattern isn't in that row, do not display the row
if ( !result )
{
x[i].parentNode.style.display = "none"; //and hide the row
}
}
}
</script>
By default I don't think that is possible.
The list web part that would show the Shared Documents understands how to render the library, but doesn't understand how to filter to only show the contents of one subfolder.
It would be nice to create a Filter Web Part and to provide that filter to the List web part so that it filters according to the sub folder defined within the fileref field of the document library. However the filters it appears to be able to consume are Type, Modified and Modified By. So you could filter it to just the documents you touched, but not the ones in a given location.
End result: Roll your own web part.
The reason is that the folder selected by the webpart is not controlled by the webpart itself, but by a querystring parameter.
e.g.
"?RootFolder=%2fDocuments%2fMyFolder1&FolderCTID="
So folders are not "real" folders as such, despite the "lie" that is the webdav interface
e.g. \\sharepointsite\documents
There should be a way of including the desired RootFolder parameter, like a linking to the page with the querystring included (far from ideal).
I do not know of any webparts that do this.
I was able to do this by creating a new Column and specifying a keyword for the entire Shared Documents list.
Then I had to add metadata.
Add the WebPart again to the page.
Create a View that enabled the display of the files as a flat list, and filter on the new Column (i.e. where Keyword is/contains ----).
Then I get the list I want on the page with the web part.
I have a work around I've used that doesn't required Designer. Not as elegant, but achievable by any power user.
After you've added the library web part, go to the page and click down to the folder you want to be the default. See that the page link now shows something like :
www.mysite.com/sharepoint/default.aspx?RootFolder=%2Fsubfoldername&FolderCTID=...
Copy that link. Delete &FolderCTID and everything that follows. In this case what remains is :
www.mysite.com/sharepoint/default.aspx?RootFolder=%2Fsubfoldername
Use this link for navigation to the page and the library will display as you want within that page. Be aware it does not replace the default view for that page.
Another way of face this issue would be to just use the Content Search WebPart ( CSWP ) and filter the results based on :
folder path
url depth
You will need a UrlDepth value that matches your requirement. The best thing is to use a high value, like 10, and then reduce until it shows just the files you need.
Regarding folder path, remove the (quotes) ", this way the query will perform a "contains" lookup, instead of "equal to":
Result will be something like this:
path:[your site]/Docs/our_team UrlDepth:7
If the folder name contains spaces, you may need to wraps it with quotes. something like:
path:[your site]/Docs/"our team"
One alternative I've used is to drop a Page Viewer Web Part on the page and choose "Folder" as the type of thing to view. Then specify the webdav UNC to the folder such as "\some_sharepoint-site\some_site\shared documents\some_folder\"
Place the document library list view web part on any page.
Edit the web part.
From filter select column "Content Type" and value "Folder"
Save and you are done.
By doing that it will show you root folder files only.

Resources