Placing Share Documents subfolder as a webpart in SharePoint - 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.

Related

SharePoint 2013 Online - How to set up a filtered column linked to itself

I am a newbie with SharePoint. I have set up a document library. One of the columns is a unique id for a document. Another column called Related Document is a lookup field that may contain a clickable link to another document's unique id.
How to automatically fill in related document column with the link to the original document? That is, if I make document A be related to document B, I would like to automatically add a relationship from B to A as well. Not sure if it's possible to do with Related items feature - it does not seem to allow a clickable link.
Thank you.
The only way I can realistically see this being done is with a Remote Event Receiver. https://msdn.microsoft.com/en-us/library/office/jj220043.aspx
I can't think of a way out of the box that would do this.
You will need to create a SharePoint Add-in and deploy it to your SP Online instance. The remote code will get hosted on an Azure instance.
The remote code will get triggered when a document is updated.
You can then get a reference to the related document and fill in the related document link field accordingly.
You can pass parameters with the source parameter of SharePoint. This is actually to forward an URL to jump back to, but can be used to automatically pass parameters to the second form of the library.
Here is a small function that opens an upload dialog e.g. to be inserted in a content editor WebPart:
function openUploadDialog(passParameterName, passParameterValue)
{
var dialogOptions = SP.UI.$create_DialogOptions();
dialogOptions.url = "/_layouts/15/Upload.aspx?List=[INSERT_LIST_ID_HERE]&RootFolder=&IsDlg=1&source=%2fSitePages%2f[SOME_SITE_OF_YOURS].aspx%3f" + encodeURIComponent(passParameterName) + "%3d" + encodeURIComponent(passParameterValue);
dialogOptions.width = 700;
dialogOptions.height = 310;
dialogOptions.title = "Submit Document";
dialogOptions.dialogReturnValueCallback = Function.createDelegate(null, CloseThisDocCallBack);
SP.UI.ModalDialog.showModalDialog(dialogOptions);
}
openUploadDialog([NAME_OF_YOUR_ID], [VALUE_OF_YOUR_ID])
Short:
Add a field with the ID (or whatever you want) to your Library
Create a Content Editor or script WebPart where every you want and use the
function to open a dialog
look at the source of this webpart to find out the DOM ID of the field
Add another webpart to your Upload Form (Ribbon => Library => Form Webparts => Default Editor Form) to take the value from the source paramter (e.g. via JQuery) and write it into the new field you've just created.
Something like this:
id = GetUrlKeyValue('[NAME_OF_YOUR_ID]');
$('#[DOM_ID_OF_YOUR_CUSTOM_FIELD]').val(id);
I used this once to add an ID of a list element to the file. Hope that this is what you were looking for.

Get listitems from Current Site

I am trying to create a Page Layout, that should have a lookup field. Lookup field should always get populated with a list's items.
This list will exist in all subsites, so whereever I create this page, list should get populated with listitems from current site.
I tried using site column lookup field, but it always point to list under top site and not the current site.
Any suggestion on how to make it work or better alternative? Thanks!
Let me know if I can provide more info.
The most straightforward solution I can think of is using a cross site lookup column and creating a seperate fields for each subsite. However, you will need to create and use different Page Layouts for each subsite.
You can use http://sp2010filteredlookup.codeplex.com/ for cross site lookups.
Solution 1 - Use http://sp2010filteredlookup.codeplex.com/
Use filtered lookup solution. So let's say you have your custom Page Layout and custom Page Content Type.
Every time you create new subsite, you should remember go to Pages list settings and edit Page Content Type by adding cross site lookup (with the same field "internal name").
So you still have one Page Layout (and one Content Type). But for each Pages library instance, Content Type contains diff fields (but with the same Internal Name). It will allow you run CAML queries and other things needed without any problems.
Solution 2 - develop custom sharepoint field type.
In edit mode, control will render "dropdown list" and populate data from list instance that is on current subsite. In the field settings you can have relative list url.
Solution 3 - hidden text field / js snippet solution
Page Content Type can contain hidden text field (it can contains selected field value in json format for example). Develop js snippet that will handle all the logic (rendering in edit/view mode, saving etc) and put it on Page Layout (aspx).
I would suggest to use solution #1 or #2.

How to restrict SharePoint WSS3 users to edit only fields that are in their dedicated views

I have a list with the fields: Title, Client, Project, Description.
There is a view for analysts with the fields visible: Title, Project, Description.
All is fine so far as the analysts work with their views and not with the lists. But when they need to modify the records clicking on Edit, they see and able to modify the 'Client' field too.
How to prevent 'Client' field to be available for editing by the group? is there a way in WSS or I need to look for 3rd party list components?
All fields have a set of properties that determine their visibility in forms, such as "ShowInNewForm", "ShowInEditForm", and "ShowInDisplayForm". There's also some for the file dialog, the list settings page, and a few other places, but that's getting past it. Short answer, yes, you can make the field not show up in the edit form with WSS without needing any 3rd party components.
If you need a field that cannot be seen in the Edit Form by anyone (that is, no one should be able to have it in their form), then you need to modify "ShowInEditForm" to be true. This can't be modified directly through the SharePoint UI, but it is extremely simple using the object model.
If you need certain people to edit it at some point through the SharePoint UI, then you'll instead have to create a custom edit form. That's a bit more complex, so I'll hold off on providing that instruction unless you state you need to go down that route (or someone else passes by this answer and requests it). Nevertheless, it is fully possible with WSS 3.0.
EDIT
If you know already know how to insert inline C# code into an ASPX page, you can perform this very simply using SharePoint Designer. First, follow the instructions from this article, especially make sure you don't delete the default list form web part. Now, in the custom list form you added, make it include every field which anyone will be capable of editing. The last step is to make the form hide those fields for certain people. Let's default them to Visible=false, and flip this switch if the user is allowed them. You can do this either by checking if the current user is part of specified groups, or by checking if the user has a certain permission level only held by people of those groups. You'll basically write some code like the following, I'll use checking for a specified group as the example.
using (SPWeb web = this.Web)
{
SPUser currUser = web.CurrentUser;
string[] listOfGroups = { "Group1Name", "Group2Name", "Group3Name" };
foreach (string groupName in listOfGroups)
{
if (currUser.Groups.Contains(groupName))
{
//Repeat this for each Control, refer to them by their ID. For example, this is for a control with the ID txtTitle.
txtTitle.Visible = true;
}
}
}
If you don't know inline code, you'll have to write a custom ASPX page with a code-behind. Copy EditForm.aspx into a new file - you should do this after setting up a Custom List Form as per the article. You could also build a new ASPX page from scratch, but make sure you include all of the necessary Content placeholders for SharePoint pages. Now, the page currently inherits from Microsoft.SharePoint.WebPartPages.WebPartPage. We need to create custom code that inherits from that class, and change the page to inherit that new custom code instead. In the custom code, override one of the OnLoad or OnInit methods, and include your check for the user's permissions there as detailed earlier. Compile the code, deploy it to your SharePoint server, and it should be functional.
If you want to set fields hidden or display them in new form or edit form page of the list...
Go to the list settings.
In Advanced Settings, enable "Allow management of content types"
By doing so, you will get a List name Link on the List Setting Page.
Open the link and select the fields that you want to hide or uhide using add or remove option.
After saving this, again disable "Allow management of content types" in Advanced Setting...
Thats it :)))

Showing the list view web part for a list in another site

I cannot show the content of a document library using a list view contained in a web part located on my root web application.
Here is the site structure:
main_site
subsite1
Shared Documents
subsite2
Shared Documents
My webpart is located on the main_site.
In this webpart, I have a Sharepoint ListViewWebPart in which I want to show the Shared Documents from subsite1 for instance, but it does not seem to work. I get the following error:
List does not exist
The page you selected contains a list
that does not exist. It may have been
deleted by another user.
What is odd is that when I debug, I can see that the SPList is correctly initialized and contains the element of my list. However at the line Controls.Add(mylistview), is where the error occurs.
Here is the code I use to bind the list to my ListView:
SPList list = SPContext.Current.Site.AllWebs["subsite1"].Lists["Shared Documents"];
ListView lv = new ListView();
lv.ListId = list.ID.ToString();
lv.ViewId = list.DefaultView.ID.ToString();
lv.DataBind();
this.Controls.Add(lv);
Does someone have a logical explaination and solution to this problem?
The problem is that the list is in another site.
It is possible to use the ListViewWebPart to reference a list from another site in the same site collection. You need to use the WebId property to do this. Here is a code example.
Another option is to use SharePoint Designer to create a Data View Web Part. This will allow you to use a list from another site or the SharePoint web serivces to pull data in. The results look similar to the list view web part and there is some powerful functionality you can use. This is the first blog post I found that demonstrates this, there should be several others.
Finally, you could use the Content Query Web Part. You probably know this one already and it is really more for displaying and not manipulating data.
Edited to remove incorrect information.

Adding fields to the List Forms - Sharepoint

I'm looking to add a new field onto my NewForm.aspx, EditForm.aspx and DispForm.aspx pages in Sharepoint Designer 2007. I've managed to add a new textbox webpart and have edited the Common Textbox Tasks to make the Data Field my new field (Contacts..)
But how do I edit Edit.aspx and DispForm.aspx to display this new field?
I've looked around already answered questions on the site but I haven't run across what I'm really looking for -- sorry if I missed it!
Thanks!
Shannon
It doesn't count as "development", but wouldn't creating a new List column, Site Column or Content Type add this additional field to all your list forms just fine? How does this not work in your particular case?
You have to use SharePoint Designer to access the site and edit those aspx (in the 'Forms' subfolder of the folder named after the list)
You are probably going about this the wrong way. You should not need to change the edit and new forms for a list just because you want a new field. You do need to add the field to the underlying list and rely on the code in the forms to display the field correctly.
IN SPD choose the Table tab on the far right, then Select a row, then you can Insert Above or Insert Below, then you can add your new field.
New item, edit, and display forms aren't attached to lists so much as they attached to content types. If you can't use InfoPath or Designer to set these up, what you do is the following:
Create the form in question as an application page. For whatever reason, SharePoint application pages won't render on-screen, so to get an idea of what I'm looking at I generally make them in a visual web part or separate ASP application first, then copy and paste the ASP/HTML over, then delete the original.
In the case of edit and display forms, SP will pass you a query string with the ID in it. I capture the item in question thusly:
NameValueCollection nvQueryString = Page.Request.QueryString;
taskID = Convert.ToInt32(nvQueryString["ID"]);
ViewState["TaskID"] = taskID;
SPWeb thisWeb = SPContext.Current.Web;
SPList taskList = thisWeb.Lists["Job Request approval tasks"];
SPListItem taskItem = taskList.GetItemById(taskID);
After adding on whatever it is you need to add on, you do need to add logic to the .cs page or a separate class that actually edits/adds the item in question. Probably pretty obvious...
From here you have three options: either create an event receiver that points the editformURL/displayformURL/newformURL of the content type in question to your application page, create a brand new content type and add the URL for your application page in its XML definition, or add it manually via Powershell.

Resources