Fillable forms in SharePoint without any 3rd party addon
Overview
Using SharePoint to offer users the ability to fill out forms and archive them in SharePoint is a very common requirement. In SharePoint you can add different type of workflows for approval etc to them. Doing this without some extra product is not an ideal solution. I struggle with this since WSS 3.0 . I will show you a solution that will do this without any cost or add on.
Introduction
When it comes to document management where users have to fill out forms in SharePoint and store them in a List or Document Library you have mainly three options.
- InfoPath (The suggested way, together with forms services a nice solution)
- Office documents (You could integrate them in the document library menu and have a nice solution too. You could also add a conversion service to archive them in PDF format.)
- You use a SharePoint form and add all fields you want to use in your form as columns and store them in aSharePoint List or SharePoint Document Library using content types.
If you have the right budget at hand, the first two options are pretty good solutions.
The third option will solve the problem too, but is not what I had in mind. My intention was to give the user some kind of “read only” document they could print and watch.
A fillable PDF form would fit perfectly to that requirements but I didn’t see any way how to automatically upload the filled out PDF document without any third party tool using the Adobe Reader. (I didn’t added it to the list of options because I have never seen this work, I’ve just looked over the products on the internet.)
What I came to was a solution where the user has an HTML document where she/he can fill out form fields and finally store a “read only” copy of the document in a Document Library.
This is what it will look like if you add a new document to a SharePoint Document Library:
Select the document type:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_tcd75do7ALf5srkfkFnCj6QmV2tuVNWYc16tlsh1L9wJ0Zar8l9hOvFoZEP4kru0jOgh5hogldn9A0x_yFAKWFvQBNvdHvoqaor7gJyhgzPnFBB-gccj4X6n3PG2t2Oczt31bFP1au5tlVB6TGyVRgk10LpA=s0-d)
Fill out the fields and upload them:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_sPCgmwyYT4rEnZAeGDihK3cHRQpHfX2eLaG0Qlpj4c4-M7HnJWXpD5MOBGRTLVtcAih1wQQadqcaOaB_PCknPLDwgbgNzmP8URPPTeDvXc75_kULwZgCf0AAPHOL9GLqD-o03kB6SLK5ZzGkTR_pIoS-uDGH0=s0-d)
Notice the document in the document library:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_viY3-zGufrk2C3YzDbyu5YIsx0-vKv2vd0fNzNS_i77sEdt5dLrGS7ZgWC1XfJDMXSwBcqYhI05BI2fqTxA91pED4a3nWab_w7-DchIpYEiO9j5AnYOEkbOXQyqjXu7OHUStuQletDs1qCJbLUD459Iizf21A=s0-d)
And finally the archived document:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_uOClybO3qxwPPlsjU7MANkLBPpBTKeTAxsHAKB8ufDm8HzqK-fOt6A9tTq9UE-pusgB9oy-BoXyY36c4CYFc7I-Ro--XI_3TRVJKfxKMTxSi-0iUNCdc-sqjbSCW_qua6FIqNP_lyhMu-YSW3lhXc4RcpnUKw=s0-d)
All this is done by adding one html file to the SharePoint folder and store document templates, images and JQuery in a SharePoint document library.
All file editing is done using SharePoint designer
Background
Technical details
All this works by adding a html file to the Sharepoint directory within the file system of the server. This redirector is needed to give us the ability to add our menu entry at the new document dialog of the document library.
Another thing we need is a space in a document library where we can place the JQuery library file. This location should be readable by anybody.
As a last piece we need two document libraries, one which stores the HTML template, the menu HTML file and the images for the menu (called SriptsAndMenus in the sample) and a second one where we would like to store our documents (called Cars in the sample). To structure the data within the library, we have to manually generate a folder for every car named by the number plate. This hasn’t be done, but it will give us the advantage that all documents for one car are in one pool (the folder) and can easily found.The sample project
For this article I prepared an archive with files that implement a requirement for a department that runs a car pool for a company.
They have this kind of forms where people should be able to fill data in fields:
Form name | Description |
Acquisition report | Has to be filled out whenever a new car is coming into the pool |
Washing report | Has to be filled out when the car was washed |
Maintenance report | Has to be filled out when maintenance (interval) was done |
Tire replacement report | Has to be filled out when tires were replaced |
Oil replacement report | Has to be filled out when the oil was replaced |
Repair report | Has to be filled out when some kind of repair was done |
Note report | Has to be filled if some kind of information for that car should be filed |
Disposal report | Has to be filled out when the car is disposed |
Step by step installation manual
For the step by step manual I made a clean installation of Server 2012 and installed SharePoint Server 2013Foundation on it, so we start with an unmodified system. All screenshots are made on a German system (preferred an English one, but didn’t had a media and not time to wait for the GB download…).
In my example my domain name is “test.local”, the server is named “server1” and the site collection name is “sc1”.
Prerequisites:
- A running SharePoint 2013 or SharePoint 2013 Foundation installation on a Windows Server 2012.SharePoint 2010 may work too if the REST interfaces is configured. (untested)
If you plan to install it in a farm environment, please notice that the installation has to be done on all Frontend servers if you have some kind of load balancing. - The attached SP_CarPool.zip
- SharePoint Designer 2013 (only if you plan to look at/modify the files in SharePoint) [It’s free and greatly supports you when doing customizations, so there no reason for not using it.]
Step 1: Configuring SharePoint
SharePoint has to be enabled to allow opening of .html pages in document libraries. This can be done in Central Administration at General Settings. Change the “Browser File Handling” option from Strict to Permissive.
Open Central Administration and open the list of Web Applications:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_sVnZbUfE52Lh34U1zhohMEHy725PVaqTOOpjtXwagfoj1F9OQPyq6heIoGgm3nqCQEVR-aCx2oLH4yroEWzhjq2OZ2WwYI8DofoNizGrk_bNDAWiNmlj0Go3QDdmktnHRu25w8qei48E1OXmbNZZeZnsl_Kco=s0-d)
Select the SharePoint application:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_v4m9ElrlX2enJwOnkjGDOyoi_oBRYGEJOZZn2futArAee58qKIpYrZcbwiL7CtWqh-1xIPJbk5UCdfeqzQSCvPqAn2L5jw915rF7eYC0UvyhQuK9NuFA3SaQXQ1FPuHjVat9GY3yNmlKX_i6mCIAr6MEVfxLI=s0-d)
Select General Settings from the General Settings menu:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_uLIxrJQgiQk09VBUhK6sbJpUdClJR5j_HtpYXH8v2LuSvCWnJktj079Ix2nAb28dvaAkdPf1MaPzQaSiazd092jWxo-oL3gxpInIJb9pFZTSk-qEbTht-vNY6OP4CSF0x4f1_dpzBkv3zaa-aU3Q6R0xiUtRk=s0-d)
At the “Browser File Handling” option select Permissive and save the changes:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_s8cocdMjkNj7VgfzbUvY0gO-S36rLjzb5nie7jJRSqLidlBRdfdar9WY4EhkUPWX-7o8owRHA8LriMc0WCH66ItyHdHct_gIENxhYqEK8tYvJm-fvA6RPtXuB53Y5AlB3zX51JBWssZyWC3KIQiPWMR6NPfjo=s0-d)
Step 2: Extract the archive
Extract the SP_CarPool archive and you will find three folders:
Extract the SP_CarPool archive and you will find three folders:
- jquery
Contains the jquery .js file and the license terms for jquery - Redirector
Contains the redirector.aspx page that does the page redirection for the user menu page as well as a textfile that describes the Targetfolder of the redirector.aspx file for easier deployment. - ScriptsAndImages
Contains the folder scripts where all the html files are located and the folder Images where all images used in the menu page are located. Please notice the license in the license file for the images.
Step 3: Copy jquery
Create a Document Library called “scripts” that is available to every user (read only access right) and copy the file jquery-2.0.3.min.js to it.
Create the Document Library:
Enter the name for the Document Library:
Open the newly created Document Library:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_sCkL7ESOOdpauN0v5fccvKzWxKOBgFwr8Cv7K9oZ3KYAZhHoUCFjQr8Mj22Eru-rQZuiRB--aBnaSfVBH-E8QkEGML6JlYcI2-o-A6gDJSyMHxdz4jzKjwwAvL9FOcUdF9nojL557UdZUnvCtw_rnQT80BpaI=s0-d)
Upload the jquery file:
Finally we have it in the document library:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_tPhMSh5WY0tjU1Jae5ITIEGjvuQ-gBsebBz44FkjIzCT5mfnM1tQaqyQQZkzrKwROjSkRhoWpwIFKgdpersZQ71eug1YLejzZeWsXRgGBIgi0kzcDxNHygKfBMtkkbCALThcWlKyVjCrWNou-hZyX6fItWB3A=s0-d)
Press the right mouse button on the file and copy the path to the document:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_tZlh0eZuqpr8W1mRwOjR5nOzinlhuDNzZvS98RoqjPqbTPj4-Skp2bSDI0f6uLB-Knxkf22qlKx4lHat5B41x_aeTeXrtZjZKjQIXtKq-JYcu-OMkQrvd6pLUilUfPUAr6yGqp8aeRfdPsi7n3ZjEyIvRh6GU=s0-d)
Press the right mouse button on the file and copy the path to the document:
We need this as it is our absolute path to the jquery file.
In my case it is:” http://server1/scripts/jquery-2.0.3.min.js ” (We will need this link in every forms document as a reference. If it differs at your server, you have to adjust it in the html files.)
Step 4: Copy the redirector.aspx file
Open the source redirector folder you extracted and open the “Targetfolder” text file:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_teau4OL6qT9yoBB5U1rAJkW2NqkCWGmNoCaXSCy-k0ekLy1AcVKiCJ8ncOYbQFL2lxF24JXSdtftjLZo6q5R6pR09DrmAspBmeXlE2ZyFzGFi8MTyrZDHl7ijDJzIMjKmYhREu46Lw0l6wQkVzrw2I8Y3xxgc=s0-d)
Mark all of its content and press the right mouse button and select copy:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_t7JNppX0U-5KXAulxAS0M2kY61r43KFAO8qnZEVvAE4THebBcpEYOuaB7Drb-0ELiZaOnZIyf-HqKIVka3wADDGiBNFUGJUa91A9CRjaPVbo4anPzcgMFV4XagLh-QcHZHzsiOdyRRpP705eSoLn0OQg2D91o=s0-d)
Mark all of its content and press the right mouse button and select copy:
Open an additional Explorer window and copy the path in the location line:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_sXz33jBWiOFI00GfKB2Ug6okknrOWXQkVS4KtHuLAMCI95T7RAt7vsSuvJBNFhSPVmfSD66TDCBDCSOjd14qrLuBYogyssCWQ7pcYcHUpHW8nS5gu32B9zQnNCGKMhZ2t39GZwN9CP9LUANsdi2yV3jevg3g=s0-d)
Now drag and drop the redirector.aspx file from the first explorer window to the second to copy it:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_tFtL4-kfrAnMEW7EPf5B9cZ-t0Z6iH45sgRif-411itTEqQ1mEod2KWCCj3dgiE2WaCCiIh-rl1_cqeM2qmr7U-BLRSLrfCOMR-nFvLPbLohw416ELqCrbtYnI31RtjSFDIfcOB10KpgX9c5lqvG2IzrrOoYU=s0-d)
Please notice that the .NET compiler is rebuilding the application due to modification in the .aspx LAYOUTS folder. This will make the next page access in SharePoint a little slower.
Step 5: Create the ScriptsAndImages Document Library
Now drag and drop the redirector.aspx file from the first explorer window to the second to copy it:
Please notice that the .NET compiler is rebuilding the application due to modification in the .aspx LAYOUTS folder. This will make the next page access in SharePoint a little slower.
Step 5: Create the ScriptsAndImages Document Library
Create it the same way as you did for the scripts folder. The result should look like this:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_vBkP50QABjsEjwtF0PNsGjQZIobOMdqNv5M4SG2z6YLj2D6SgqHtTzk_prTBIRKJ9gyWr-Qy9Oq7S2BpnANeYjRIVzBsRaWo7I-76E1d0wE36q-zoAvLwRAhsSw9wKmwthqtABV7Br4j1VNQTgQabylLzHXLs=s0-d)
To copy the files switch over to SharePoint Designer by using the SharePoint menu:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_tmk3zbUc3poHiu65QTvnAqYn1JzM2Zs9ME5wuZuQPjuO-2hG7WBESlPeE-NwgNtlvSSAIqjr8kfOWf-nylkPl9b87Ai76K3J8QXHhb0Zpedx56gWKWruQV1KQw0uiF9An3qurBbgxH3xJQGXaVnRM4cXdwpY8=s0-d)
To copy the files switch over to SharePoint Designer by using the SharePoint menu:
In SPD open the newly created Document Library:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_vhK9lHN52fI8LsXZw3-kQJGigv35kQsFS8C58p4udlwkaubom0igpPXtIT6AlpflygwvpGp3eco2QMzePPkYkyWPjfP02bhPIRGjr3j_zTNd69ohRcVTyrIEI2sLO2O4Gz93V-8qkfMQ0Uzf1I80aTd-FJC54=s0-d)
Now drag and drop both folders from the extracted archive to the SPD window:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_uVd30Q9O_nAwHtOKzHLy_Em4ps496nY_-SeULkIPy80rH7-G1kpUIaf2sLeJT1L_3_Hv98oWtkKHq359WuECSWQS9iXXOQAuicl5ARGT2oKxq6-k8w5JamCNEXGtrIJrwdUTWQU3dZ7ys-AjEjOaUM_SKx4dc=s0-d)
Now drag and drop both folders from the extracted archive to the SPD window:
The result should look like this:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_vapbP-WPA8hbMhYke9y1HgE6QNhz0sMdQAFCer1Y86Gi04BO9q5_REPtKLNoDCVoG17noaShZpnO8OXIiR_0SkhkWKtPQ71nnCujm3fylrFWTHCrtmoeJIH23HSI6wk_wxO5DiqL-FPafXYK0WVX2bx3ZZpQ=s0-d)
Step 6: Create the target document library
Create one last Document Library called CarPool using the Internet Explorer (or SPD, the result will be the same):
Add this folders to it using the add folder function:
- 555-SHOE
- 415-MIAMI
- 123-TEST
(Each folder will represent a car within the pool.)
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_tqkD5FdMRWTBTInJI92u0MBAX3BboPSh4EJ2Ugz2iWNvIjSKFkBqrNmR7ewQ3JM9X7f1DGiErUY0eWjNkqegt4NYo4PaWsXLehWk4h7JzGh45k6Zor8gFQSadVhnxzPe_RH2FDBQH0ce1m6cFPXSN0xAReJZA=s0-d)
Step 7: Enable content types and create a “New Document” button
To enable content types select the CarPool Document Library and open the Library settings:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_uT8EC_RflHDcQBicTfaRMB1xFG6AXNNhw4mdzwfvy138LqrW0wi75qYSZ04QI3sIjg1EIJDK-ErWwh800fF4wig3HiYEmlNQpKHJi3mb0yznmzOC-ktasfMjqDw4ptIsAMcu5jt0knS908GMOxoIBjbqak4w=s0-d)
Step 7: Enable content types and create a “New Document” button
To enable content types select the CarPool Document Library and open the Library settings:
Proceed to the advanced settings:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_uF9HkibtDPwnEuuTKLPJMkLfaj2UwqYorB4AElryaRehY57euioxutma34newzD90h5CtLfgs4dEjxS8x3lmEZqILrknjr3nL7XbIbZXllFItxfLCYJYSH9RoMhDKbgATrBuhQyzkO4hrugAB_VBy3I8a5ISE=s0-d)
Set allow content types to yes and don't save now:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_vqGzpPVpthJAhMjwVpsy9s0YDc_blqSvnuyGI1XeaLyzXcKC2z9TijZuaRh4hGHcr22wsU0qGsxFyBem4Gds8ctzQvEdRex5fdww_2Q3pJDPLTRquZijG67Xk92BgIwuL6zIFUVgxemeGRAIjBTACPK3C9zI8=s0-d)
Scroll down a little bit and enable to open dialogs in a popup and click OK to save:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_vWBuVYVjpSiLOxbmae108itRzKtxg6Gqe8lLW09rRQY_JfCtLjUylmX-JFmxyBNh7mMRfpjyyB-12Wt4u_HdQZ94vQse0Clm9enmfpFbjyDAc1bzbwyRuU=s0-d)
Scroll down a little bit and enable to open dialogs in a popup and click OK to save:
In the next step we have to create a new content type that shows our custom menu when selected.
For that scroll a little down at the page you are now to Content Types and select Add from existing Content Type:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_uj8ePO6nlOny8iVXddIWGG2_XOKnGravebQPJ6ei4OxIVBNd92eHlVABcYHpOu9ExxpbON8srW2AaSoReNrAXsFaPADj10eyVVWSXGQxiIJktrFmCL_wqsFV9W70lA-Cy6ARzyNiAQA5V7JYqTrfTrKtLgHYg=s0-d)
For that scroll a little down at the page you are now to Content Types and select Add from existing Content Type:
Select Link “To a Document” as the base type:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_tnaGjI7FTMYGJrUq39vOKBtcoH0y75POzoKFsDzGxxny3bPKftkvY9ePDAHahfNUOpURVbF84yMzX097J8d0LEO6wnf1qiQZgh5XTNDSZLrOitO7U1CbOQkdvdwVMpkYkC3z24xaihlq5wI9WCAbmlqNKrpA=s0-d)
After pressing O.K. you go back to the previous page. Scroll down again to the content types and select the previously created content type:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_v7kjwx8xRLXbeNUbpzNnk1Kv9200U9m1ImLWa4hWyrEWoL8oUaoKxKc90BAqs94uHoKll2UZZSuRpsLYBMkEU8rIgMz3WYD2Uvsq-xbsSoyGg7mFMdhqzJH5VCOVmBifL_ns35wlbRnjBuzcIZmS2T8mOMm34=s0-d)
Click on Name and Description to provide it with a name:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_vs4m5V7SOMn9PFwEB3RE1Wkfd90dIGs4MS14BZ_qt94hdnnsEHe5cW5wwNUbCSvVVDqQlBaGrwjrO6X_RW19v1m6LVWZl15PUIgY2kIKWDfdy8Xf3DwdAjvqUTtaLLNByqVB7uaf3rgNgJVyjvRg6WiC3msE0=s0-d)
Enter the name and the description:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_u5IdKyEQX76EXtF7Zm_rvLhECX6mPZSuAFT9L8y_7ADlla7u_a8yEFVhu9uBrcATF2a6Woi5G86yFEiDVoeALfPZj_-Q3g3XEjBzMayvbwvoIOPol5Om-5ds7ciV6QzbLhO__i3t8XIlppQEE6j8uaf8NaIw=s0-d)
Enter the name and the description:
Open the advanced settings:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_vQ6_pr_-iQ9_MdtiRWM_A9xTFbA2liTFM2-wcA2lZN7S5pxr-meErP_BaaQiUlFfmsifSNuRgq6QAzIe2XQrxfSLidwf6B99VQTeZ5vO6-KXxtxv_fT74=s0-d)
In the document template link add this URL:
/_layouts/15/Redirector.aspx?newurl=http://server1/ScriptsAndImages/Scripts/CarMenu.html
(It redirects to the CarMenu.html page vie the Redirector.aspx.) :
Use the back button several times to come back to the page with the content types and select the “Document” content type:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_u2cvk4PlcnhwO93LMcRURRDlWvC0MisqkvLBaH-YLjSRwW-2v0OmMEmoai4vLjtsALD5FsqfLaiHr3vvrJvbO_ku3oNXMWWH9Nu5AVV9mSyJeIzhcnKj7yvUuhQ92x1wRaLiBD6nJMlfx6E3Qg-_J8a280PA=s0-d)
Delete it using the “Delete this content type” link:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_sGspVILgHD4M8pOjxXCfK0Owy2rFYWvZN2suyu-6YhHadJVQ_CFkIPsFz_Rwn3X9SvTfx12UdHx2rWP5Qs8HxbAjMyJZ2aEv6saAWj7xBofrSwC7P7v30=s0-d)
Finally we can do some tests by adding a few documents:
Finally we can do some tests by adding a few documents:
And instantly a tire replacement:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_tZ0rsKZP2egGxeREgrf3YoeTjHaQOS6Z5tWmBfBeutJKuzxhL8pMFIQAHSF44h-Js1dQJJP74YG8wus3Nb2yXuE8wMdEJnHjg_oXaP1TJjux7EkO829SQM9G4949Bk4WXWWIBnEthV2yK30zLYZ98AWEAqDg=s0-d)
And when we open the documents:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_t1keUJBbX_KYAsQBZyoO8_b3ShsAf5xdQdcBWBpLahJBRyX4Lwny1ZZJm9Cp_-If9mabmcbWCBVSChXkXnTaLrLqu5QyDo3-gZtmMWPYO0n-NS4NI3k_o2u---g-r2WLHrYIaLxjaIlqSqWX4zZEsDkL3bxg=s0-d)
Using the code
How to use it for your own projects:
First of all let’s check how it all works: We have a webpage (CarMenu.html) that was bound to a SharePointmenu button using a custom content type. That webpage loads a form where the user is able to fill data in.
When the user press the save button, the document will be transferred in a read only state and uploaded to a Document Library for later use.
Think about your process. What kind of documents do you need and what fields have to be filled. Do you need some kind of document isolation (like the number plate numbers) or can all documents go in one big pool.
When you installed the demo project, you already have most of it. Just create a document library and copy & rename the CarMenu.html and one of the form documents (e.g.: Car_Acquisition.html) to it. This would be your base where to start. If you have only one or two documents in your process you might don’t need the menu popup. In that case just create multiple content types and link directly to the “new document” pages. If you plan to use a menu than you have to adjust two code parts in the menu file:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_ubaRdTEQJ_LTHo_S7MKF7NBrOBMtbqfu9ysbW5GJz3hzZ_zkH0rg34B_djttAIPuMdDzMSF1TlyP_EJp6byFpKt5MaVcD6aCSPtYcSihffSiD_HhSnNvGwAjVnP8u3ePrGCqIMyNQqpdZK54LyMZFYuUrUJw=s0-d)
First of all let’s check how it all works: We have a webpage (CarMenu.html) that was bound to a SharePointmenu button using a custom content type. That webpage loads a form where the user is able to fill data in.
When the user press the save button, the document will be transferred in a read only state and uploaded to a Document Library for later use.
Think about your process. What kind of documents do you need and what fields have to be filled. Do you need some kind of document isolation (like the number plate numbers) or can all documents go in one big pool.
When you installed the demo project, you already have most of it. Just create a document library and copy & rename the CarMenu.html and one of the form documents (e.g.: Car_Acquisition.html) to it. This would be your base where to start. If you have only one or two documents in your process you might don’t need the menu popup. In that case just create multiple content types and link directly to the “new document” pages. If you plan to use a menu than you have to adjust two code parts in the menu file:
The first one is the title that is displayed at the top of the menu, the second one is the menu content. The format for the menu entries is the shown image, followed by the menu entry text and at the end the documents URL that should be used when clicking the menu item.
In the forms document that are several points where you have to do adjustments.
In the forms document that are several points where you have to do adjustments.
The page title:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_vrE2g_zbxXhvfc-hz-gAfB_pEkFemFEnP8pwrs0xV1mDNX9dc-QjbwzbXzceQ6njeWqP3bpyp8cJhgEiryUwNy2zaPIe7WxHaeyiHc4sIEWZBm_gRNryrsHT8erEWWmQ5KanPVcGm18XIrDfLDW5w2pX2eZr8=s0-d)
Just add a page title that describes the process.
Document specific settings:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_uifuQZpDG1z-4A4nY3PBu3tat9t8_5EM16Pg0KQ9RH0MD_fsscaooX1Mlpgyk7WWJjjM68h--fws1n_1IsiBZIFIFCZyjNSP1T4yOZ7YBl65b2zxh1us8-h6trwTBT-SeiBBNorAWXuZIVk3FyJvzTcth8azA=s0-d)
Most settings are done in one code block:
Just add a page title that describes the process.
Document specific settings:
Most settings are done in one code block:
- In the
mandatoryFields
array you can ids of fields that should be checked for any input before the data is send to the server. Please have in mind that you have to mark the fields as mandatory by yourself (I use a red star for that). - The pathOfSite has to be filled if your site is deeper in the SharePoint hirarchie.
- Tha nameOfDocumentLibrary has to be filled with the name of the Document Library where the document should be stored. Spaces have to be replaced by %20 !
- The showSubfolderSelector enables/disables a dropdown box that has all folders at the top level of the Document Library. Folders that should be hidden should have a name starting with “Z_”.
- The targetFileNamePrefix and the targetFileNamePostfix will be used to build the filename that the document get in the Document Library. The Format is: “Prefix_YYYYMMDD_hhmmssPostfix”.
And finally we need the HTML form itself. It will be defined at the end of the document between the pagecontent tags:
Defining an id for the control:
If you ever plan to use the data the user entered in any other system than SharePoint, than you should define for all input tags a unique id, because controls value that have an id will be stored in a JSON variable which can be parsed in the final read only document:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_s8leN9yPlrR0QsTew_8cpd_SdAtxq8gMYq6Hi2xMuOp7M4QAgNoxfv8a0IiVOV2RagVsAU8YJbKxXUOZ2MAvJkXnD2Xk-mQCOJyO1eseBs4_cY3AuKNxXLBc3o8XGmPXoimYpeMcdLHWnLsybjIYSBgpVrlv0=s0-d)
Going back instead of close the popup:
If you ever plan to use the data the user entered in any other system than SharePoint, than you should define for all input tags a unique id, because controls value that have an id will be stored in a JSON variable which can be parsed in the final read only document:
Going back instead of close the popup:
In case you don’t want to use the forms in popup mode, you have to uncomment the history.back and comment out the
One last advice: If you plan to edit the page code, use SharePointDesigner. Not because I’m getting money for beating the drum for it, just because it makes a lot of things easier and the code completion will help too.
window.frameEelemnt.commitPopup()
. This will cause that the browser goes back in history instead of closing the popup frame.One last advice: If you plan to edit the page code, use SharePointDesigner. Not because I’m getting money for beating the drum for it, just because it makes a lot of things easier and the code completion will help too.
Points of Interest
Most of the code is straight forward, but I want to show a few code parts that are worth of mention them.
Stealing the digest:
Stealing the digest:
Hide Copy Code
$.ajax({
url: "../_api/contextinfo",
type: "POST",
headers: { ACCEPT: "application/json;odata=verbose", contentType: "application/json;odata=verbose" },
success: function (data) {
if(data.d)
{
digest = data.d.GetContextWebInformation.FormDigestValue;
}
},
error: function (xhr) {
alert("Error getting digest:" + xhr.status + ': ' + xhr.statusText+ "\n"+ xhr.responseText);
}
});
How could you save a document to a SharePoint without authentication/authorization?
You can’t!
But when the user is at a point where she/he can access the form, she/he is logged on to SharePoint. We can “steal” the digest (some kind of session cookie) and use it to upload our form.
Upload the form (or it kept me away from my rest
):
The code that does the upload process took quite a while until it worked.
The code that does the upload process took quite a while until it worked.
(Sorry, but the code formatter made errors here, so I add it as a picture):
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_uo0Ug_nelHC_8kdMn9EaKIi3LEg1uKuqaXnFHa8p7XhKH-Lbwn-M5gcKueE7B_Cd8qIEeCDOchvylpJuHwhzzlmGPJ4w3_2Y6CsJXCnpPCyHclNIDbEUUA=s0-d)
All it does is using the SharePoint REST interface to upload the content. Getting the right format, so the server accepts it was a work of trial and error. Conclusion
It’s not rocket science to set up a HTML form based system for archiving documents in SharePoint by using jquery and a little HTML with JavaScript. I just put together all the pieces in the hope that it is useful for you too and the whole is more than just the sum of its parts.
No comments:
Post a Comment