Programmatically Updating a document library in Sharepoint - sharepoint

Im quite new to SHarepoint. I have a requirement like, i need to move some documents from different document libraries to a document library named "Region". So that each time a document is updated in these document libraries , the document should be updated in the library "Region" as well.
I wrote a c# function in a class library,to copy the documents to the library and added the dll to that sites Bin folder.Function is working fine. But Im stuck up , Im n ot sure where to call this function.In which event should i write it, so that each time any of these documents are modified, that change has to be reflected in the "Region" library .

You have to create a SharePoint event handler and attach it to all the document libraries where you change the documents. You will then override the ItemAdded and ItemUpdated methods to perform the copying.
See more info in this StackOverflow discussion: SharePoint running a method when item added to a library

Using an event handler is probably the best way to go as mentioned by naivists. Alternatively, if the work you are carrying out is part of a larger whole, e.g. a Workflow, then you may want to consider creating a Visual Studio Workflow, which may be quite complex to get started with, or use a simple tool like the Workflow Power Pack that allows simple C# snippets to be added directly to SharePoint Designer Workflows.
Have a look at these articles. More info can be found here.
Note that I worked on the Power Pack so I am biased. Having said that it works great ;-)

Related

xpages display the document history

In some 'old' lotus notes applications, we created a history of each document: who created the doc, every person which edited it + the respective dates. The code contained several libraries in lotusScript.
For xpages, is there any snippet / sample working example which I could use? I found this but I couldn't download any example ...
ValueChangeListeners allow you to capture changes to specific components. I've used them to create audit trails in customer applications before.
Tony McGuckin has an XSnippet for it:
http://openntf.org/XSnippets.nsf/snippet.xsp?id=server-side-value-change-events-listeners
Declan Lynch covered it in a blog post:
http://www.qtzar.com/using-a-valuechangelistener-to-build-an-audit-trail/
Don McNally has also done a blog post:
http://dmcnally.blogspot.co.uk/2013/02/xpages-detecting-and-logging-field.html
I don't know of any pre-done snippet yet. But this becomes a lot easier in XPages especially if expand into Java. When I create an application these days I basically convert the document to a Java object. I don't do this yet but it would be easy to store in the object a Map of all the fields and their current values and then on save, look for differences and then write them out to a log document.
this could be done without java of course. Create an map object in scope. Populate it on loading of the document and on save do the compare and write.
Something went wrong with that project on OpenNTF (don't ever use an ampersand in the name). I'm the original author of that custom control. AFter some digging I found a direct url to the project here.

How Do You Create a Page that Selects and Clones part of a Document Library in Sharepoint 2007?

I am trying to set up a MySite allowing individuals to create and modify multiple projects, each which will contain a partial copy of a master Document Library. I have already created the Library and uploaded the documents, and I have a page on which I have been experimenting with how to do this.
I need to be able to display a list of the documents in the document library, allow the user to select which ones they want, and then when they click on a button, I need to initialize the database with some information about that prjoect, some information about each of the files, and the documents need to be copied to a new location, so that the user can pull them up and edit and save the changes that are specific to the one project. Also we will need to be able to be able to add/remove them through a similar interface after the project has already been created, if possible.
And, unfortunately, anything at all that uses code has been restricted; so, we can't use anything that will require anything to be installed in the GAC, and I can't even use any server-side scripts within the ASPX file. It seems like almost everything I find when I search for "Sharepoint 2007 clone Master Document Library" or the like involves using code.
I have been playing around with things in SharePoint designer for creating the UI, and I figured out how to get a list of the documents to show, although I'm having a hard time duplicating it. It created a <WebPartPages:DataFormWebPart> with a <SharePoint:SPDataSource> in it. However, when I've tried to pull over things like a Data View CheckBoxList to the document list, either it just won't let me drop it (this includes anywhere on the form, not just in the document list), or, as expected actually, it doesn't actually bind to each line of the list. It's not entirely clear to me what to do to create this.
I do get (more or less) that you can bind the controls via the .xslt in the form, but I'm figuring it's got to be simpler than writing them by hand since the designer looks so much like the Visual Studio designer. I am having a very hard time figuring out what exactly to do to get any of the controls to work, though; most of them have the same issue as the CheckBoxList and won't even drop on the form. I'm assuming there's a panel of some type, or some other thing, that I need to add to the form first, but this is so different from what I'm used to that I'm having a hard time even getting my bearings.
So, can someone point me in the right direction here? I'm going to need to be able to create the projects, select the documents, copy them over with some other information into a new project, including creating some items in the database. I have been developing software for a long time, on many different platforms with many different languages, although lately it's mainly been WinForms, with a fair bit of .aspx stuff (but nothing too fancy), and it's never been this hard. I figure there's just something I'm not getting about the model here; like, how do you tell the form you want to use x/y/z control connected to particular datasource? How do you tell sharepoint to create a new location for the files? How can you submit the selected files once you have them to Sharepoint and tell them where to copy to?
Any help would be so appreciated I have been tearing my hair out for days. :)
You might have had a change with SharePoint 2010, as there is a javascript/jQuery programming model, but without that you don't have a realistic of coding what you will need. You may get lucky and be able to call the SharePoint web services using jQuery, but it is going to be a lot of work to get around a "no code" requirement.
Okay, well, I was finally able to get this mostly working, although there are still some issues with displaying the data once I get it back; I will try to update this question once I have a better answer for that.
There's a cool library called SPServices which combines with JQuery to give an interface to the web services for SharePoint 2007. It seems to more or less provide an interface to anything that you need to do to use the web services without a lot of extra work on your part.
For example, to query a document library, I set up a function something like this in a helper class (based upon the examples from the SPServices documentation).
ServiceClass.prototype.getSpecialDocLib = function (onComplete) {
var sc = this;
$().SPServices({
operation: "GetListItems",
async: false,
listName: "Special Document Library",
CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
completefunc: function (xData, Status) {
var outTable = new DocTable();
$(xData.responseXML).find("[nodeName='z:row']").each(function () {
var i;
var outRow = new DocTableRow();
for (i = 0; i < this.attributes.length; ++i) {
outRow.addField(this.attributes[i].localName, this.attributes[i].value);
};
outTable.addRow(outRow);
});
sc.onDocumentListComplete(xData, Status);
if (onComplete != null)
onComplete(resultTable);
}
});
};
For copying a document library from one place to another, I believe you can use Lists.AddList to create it, (not specifically documented in SPServices but is based upon this Web Service call) either from scratch or a template, and I believe you can use the SPServices Copy.CopyIntoItemsLocal method.
Anyway, I seem to be making progress with this so far; I will update and accept this answer once I have a little more experience and time to make sure everything works, but so far I seem to be making progress toward the "no code" goal.

Template item in simple SharePoint list

We don't do any SharePoint development, but I was wondering if there's a way in the web UI to create the ability to copy an existing list item as if it were a template.
I don't think there is any way to do that without at least some code or using SharePoint Designer. In code it is fairly simple to do, but I don't think this is what you are asking for.
You could switch to datasheet view and then use copy & paste, but that isn't really a great solution either.
You could use a SharePoint Designer workflow to create duplicates of an item through the WebUI, there is an example of this here.
We have this capability as part of our product. The product is called Smart List Lite, it is free and it also install a new custom field type called Item Copy Field, I think this is what you need
http://www.infowisesolutions.com

How to create a shared document library in SharePoint that can be used in subsites?

We want to create a common document library on a certain site level and then create views on that document library in the different sub sites?
Is that possible in SharePoint?
Can it be done declaratively?
Rine
I would recommend to use the DataFormWebPart (requires SharePoint Designer to insert and customize the DFWP, the result can be exported to a feature)
The following blog entry lists a suitable SPDataSource sample:
SPDataSource and Rollups with the Data View
Good Luck!
Not out of the box. You will either need a third party "roll-up" ("roll-down") web part or you will need to write your own. OTB, views for lists/libraries are only visible at the current site level.
That being said, roll-ups (in one form or another) are probably one of the most common 3rd party seller for sharepoint (just a guess). In fact, I would bet there are several free projects out there that you could use (Check codeplex). You should have no problem finding one that meets your needs.
My suggestion would be to write your own, as this would give you some real good experience using the SharePoint object model and there really are no complicated concepts. Once you get past being able to do site navigation and accessing list data through the OM, you pretty much have all the tools you need.
Good Luck
I have found a cheep and great webpart which does a documents rollup from all subsites with search, paging and sorting functions.
http://speasysolution.miiduu.com/es-sharepoint-2010-documents-rollup
i used it, its simple and powerful

Sharepoint 2007 with MS Office 2007 footers

We had a need for a document management solution and were hoping SharePoint 2007 would satisfy our needs. We felt our needs were relatively simple. We needed to manage versioning, have searching capabilities, and having an approval workflow.
SharePoint handled these three aspects great out of the box.
However, we also require that the footer on the Office 2007 (Word, Excel, and PowerPoint) documents reflect the document version, last person to modify, and last modification date. These things can be done with office automation, but we have yet to find a complete solution.
We first tried to do it on the checking-in and checked-in events and followed this path for a while, however, the complication we ran into was after we made the changes to the document we had to no way of preventing the save from updating the version number. This resulted in something similar to this:
Document checked-in – the document version should be v0.1 however it is v0.2 because we save the document after the footer is replaced. If we look in the document history we there are 2 separate versions v0.1 does not have the footer v0.2 has the footer but it says v0.1 as that is the version the document was when it was replaced.
This is an unacceptable solution for us as we want the process to be completely handled on the user side so they would have full control to revert back to a version where the footer would be incorrect and not contain the correct data. When we attempted to create a custom approval/check-in workflow we found that the same problem was present. The footer is necessary so that hard-copies can be traced back to their electronic counterpart.
Another solution that was proposed to us was to build plugins for office that would handle the replacement of the footer. This is inadequate for our needs as it requires a client side deployment of our plugins which is undesirable by our clients. What we are looking for is a clean solution to this problem.
Here is a blog post which seem to be exactly the solution of your problem.
Basically they create a custom field in the document library and use event receivers to keep the current version of the document in this field.
The "trick" is that on the client side this custom field shows up as a property of the document the value of which you can easily embed into the document's contents.
I'm not sure why changing the field won't increase the version of the document, but I guess it is because you're only changing metadata, not the actual document.
They do use a little VBA script which runs on the client side, but it doesn't require any client side deployment as it is downloaded with the document. However I'm not sure if any security settings changes on the client side may be needed to allow the script to run.
Does this information need to be in the footer? A lot of the information is available within the Office 2007 application. If you click on the round button in the upper left, and select "Server", you can view the version history, a lot of the other properties are available by clicking the round button and opening the "Prepare" menu, and selecting Properties.
If this information must be displayed in the document footer I would investigate creating a custom Information Management Policy. This may be a good place to start.

Resources