SharePoint 2013 Development Document management fields small notes

Source: Internet
Author: User

Objective

Recently, there is a requirement to manage documents in a list repository, requiring multiple document management, versioning, and the ability to authorize individual licenses and other basic operations. Thus, the development of a custom section, here to introduce the idea of the field, there are some problems encountered, in the help of the group has been resolved, thanks to the group of Friends [Sydney]jay, bearded handsome.

Ideas

First of all, the idea of a custom field, since to manage the document, you need to use the document library, so in the solution with a document library, open version control (the document library XML has this attribute versioningenabled= "true");

Second, create a field, inherit from SPFieldMultiLineText, initially want to save a lot of things in, chose to inherit from the multi-line text type, and then only a GUID value of the field used in the association, so think of a single line of text may be better. If you have not created a custom field, you can refer to my blog at the top of the development series, there is a field development graphics tutorial;

Again, create the Basefieldcontrol class and create a foreground display control, the Ascx control, with display templates, edit templates, JavaScript, and Ajax;

Then, create the Application page, to upload and delete the document, that is, to manage the document, the use of the SPGridView control, and then there are version control pages, because they are lazy, So version control uses the Version.aspx page that comes with SharePoint, and then it encounters some problems;

Finally, the above is basically the general idea, may be such a hasty look more tangled, let's visualize the following with the picture below, lets ' s go!

Graphic

During the deployment, the activation site feature and so on, we only describe the relatively important part; Add a field to our list (because we are developing a field), choose a deployed field, if the deployment is successful but not, try to start IIS, or recycle the application pool, such as:

Then, click on the new project, our field has been created successfully, click on edit attachments can go to the management page, of course, this word or I casually up, because I did not think of what to call, waiting for the manger to comment, such as:

Go to the admin page, where SharePoint's own modal window is used, of course width and length are my own guess, Khan! Inside the page is my definition of the application page, that is, the upload Control +spgridview control display, using the modal window of the Dialogreturnvaluecallback property, when the modal window is closed, refresh the value of the editing page display;

Upload function is very simple, is the upload control +button, nothing to say, background server-side object model, overwrite upload, and then the same name will produce the version; Here is the diagram shown, I uploaded several documents, such as:

There is nothing complicated in this, is to download (link of the document links), delete (delete executes a JavaScript method, pass in the project ID, and then JS call a background method, according to this ID delete, and then refresh), Version control (link to version control page, another based on SharePoint's own version.aspx transformation);

In fact, I want to say a bit about delete, do not know the method is not very good, is in the SPGridView production of HTML, the format of the script, such as:

Then use the script to call backstage method to delete this id=16 project, if everyone has a better way, look forward to message to me!

Then the version control page, which has already been said, is based on the/_layouts/15/version.aspx of SharePoint, and then hides the left navigation, ribbon and other things that you don't want to do, and put it into link display, such as:

Talk about the approximate structure of link, but also reference version.aspx spelling, the first is the page address, then the list of the GUID, then the ID of the project, then the file name of this document, and finally I define the return link, that is, go back Attachment The address returned by the lists button;

1 /_layouts/15/sharepoint.attachmentwithversion/versions.aspx? 2 list={9d0234b8-23c4-4f4f-bc5a-f21908aaba79}& 3 id=16& 4 filename=1.png& 5 sourceurl=/sites/jianyu/subdemo/_layouts/15/pwc.sharepoint.attachmentwithversion/ Uploadpwcattachments.aspx? attachmentsid=8638db30-133f-489e-8139-4abd36b0785f

Focus on the transformation of this page, I think for SharePoint follow-up development is still helpful, in fact, I also because lazy to dig a hole for themselves, not poor, get to the point!

In fact, this page is very useful, changed the style, hide some unwanted things, plus a return button, has been formed; in his elation, found the problem, all functions are OK, normal operation, but found that delete all Versions, Restore, Delete Several functions, after execution, return to the default version.aspx page, instead of my custom page, this is a panic;

I first think of JavaScript problems, and then according to F12debug found Core.js problem, and then custom a core.js to this page reference, make changes (do not change the default, it is possible to impress the default function, it is possible to hit the patch is overwritten!) ), I studied for half a day core.js, then the bearded handsome Jay sent me a link, and then suddenly dawned;

The execution process is done by core.js the script inside and then sending a reference to call The default version.aspx, and then the background processing after the show, the general idea is this, the background itself decompile the Microsoft.SharePoint.ApplicationPages.VersionsPage file, found that it is really a problem of communication and background processing, and then found a solution Way!

Find the script for restore, in core.js (the default layouts below), I used the Format tool, formatted into normal format, such as:

The analysis finds that the problem of parameter B in Submitformpost (b), the default is the following format, Submitted to versions.aspx for processing, and then show, so will definitely return to the default page show, so I first replaced this address for their own definition of version.aspx address;

/_layouts/15/versions.aspx? Filename=banner%2ejpg&list={4059c14d-b1ee-4216-828d-429ef5271d52}&id=10&col=number&order=d &op=restore&ver=512

It was then found that all the problems were caused by the internal method public string Sorturl (string col, string order), which, after processing all the requests, jumped to an address that was generated from the default layouts directory, Khan!

Then I found the Restore method in the background and found it in the last line of this. Refreshwithoutop (); jump in;

Refreshwithoutop () method, so combined with Core.js and anti-compilation tools, clear the whole process of operation, and then is to solve the problem, to here, in fact, has been tossing fast for 2 days, tangled Ah!

After the process of study, And in turn see Core.js, found the front desk JS How to call this method, which is said before the parameter B problem, the following line is I modified after the parameter B, the replacement of the processing page (A.httppath), OP is the way to pass in the backstage method, Itemtable.getattribute is when Pre-project information;

var B = a.httppath.replace ("_layouts/15/versions.aspx", "_layouts/15/sharepoint.attachmentwithversion/ Versions.aspx ") +" &op=customrestore&ver= "+ itemtable.getattribute (" Verid ");

At this point, find the solution, that is, the OP came in the method of restore to Customrestore, in my custom version.aspx page of the foreground to redefine the Customrestore method;

Modifies the called this. Refreshwithoutop (); for this. Customrefreshwithoutop (), then add the Customrefreshwithoutop method in the foreground, then define the public string Sorturl () and the public string Sorturl ( String col, string order) method to modify the builder. Append ("sharepoint.attachmentwithversion/versions.aspx") so that when it is done, it will jump to our custom version.aspx page, Emma, finally finished!

Then there is the time to close this management page, how to synchronize the new page/modify the page field value of the problem, here, I used the Shutdown event, to call an AJAX update this value, feel very stupid, but there is no way to do, hey!

Later encountered problems, in the custom master page, when the call event is not good, do not know why, there is no debug error, so on the edit control added every 3s refresh, if call failed, every 3sCall once, It is not clear whether there is too much impact on performance, hey ~

The above is basically the development of ideas and display, there are some problems encountered, of course, the idea is a bit messy, indeed, the development process although they have a small design, but still feel messy; Well, the later is still to be optimized, take a look at the Dispform page and AllItems page display!

AllItems page display, public override string Getfieldvalueashtml (object value) field in this method to do the show, nothing special to say, hehe;

Dispform page display, such as:

Below, describe the file structure of the solution, such as:

Summarize

A recently developed field, the process and the problems encountered in the record, it is a small accumulation of it, there are many unusual but very useful things, but also hope to have the necessary people some reference, hehe! Come on, ~~sharepoint~~.

In fact, I wrote this blog, back to look like a messy, it is also very messy, back to improve the function is also a lot, such as the rights control or need to go to document page management, hehe, first such, the following things, continue it.

SharePoint 2013 Development Document management fields small notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.