Articles about European Sharepoint Hosting Service
Posts tagged trick

SharePoint 2013 Hosting – HostForLIFE :: How To Add Image Upload Control In React Quill Rich Text Editor?
Mar 17th
Steps
1 |
npm i react-quill |
1 |
import ReactQuill from <span class="string">'react-quill'</span>; |
1 |
var quillObj: any; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
<ReactQuill <span class="keyword">ref</span>={(el) => { quillObj = el; }} value={<span class="keyword">this</span>.state.Description} modules={{ toolbar: { container: [ [{ <span class="string">'header'</span>: [1, 2, 3, 4, 5, 6, <span class="keyword">false</span>] }], [<span class="string">'bold'</span>, <span class="string">'italic'</span>, <span class="string">'underline'</span>], [{ <span class="string">'list'</span>: <span class="string">'ordered'</span> }, { <span class="string">'list'</span>: <span class="string">'bullet'</span> }], [{ <span class="string">'align'</span>: [] }], [<span class="string">'link'</span>, <span class="string">'image'</span>], [<span class="string">'clean'</span>], [{ <span class="string">'color'</span>: [] }] ], handlers: { image: <span class="keyword">this</span>.imageHandler } }, table: <span class="keyword">true</span> }} placeholder=<span class="string">"Add a description of your event"</span> onChange={(content, delta, source, editor) => <span class="keyword">this</span>.onDescriptionChange(content, editor)} id=<span class="string">"txtDescription"</span> /> |
- In the above code, you can see [‘link’, ‘image’] in the container options. When you add an Image in the container array, it will display the image upload icon in the rich text control as shown in the below screenshot.
1 2 3 4 5 |
handlers: { image: <span class="keyword">this</span>.imageHandler } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<span class="keyword">public</span> async imageHandler() { <span class="keyword">const</span> input = document.createElement(<span class="string">'input'</span>); input.setAttribute(<span class="string">'type'</span>, <span class="string">'file'</span>); input.setAttribute(<span class="string">'accept'</span>, <span class="string">'image/*'</span>); input.click(); input.onchange = async () => { var file: any = input.files[0]; var formData = <span class="keyword">new</span> FormData(); formData.append(<span class="string">'image'</span>, file); var fileName = file.name; <span class="keyword">const</span> res = await <span class="keyword">this</span>.uploadFiles(file, fileName, quillObj); }; } |
- When the user clicks on the image icon of rich text control, it will call the above method. This method will create a control for file upload and call on the click method of file upload control.
- So, on clicking the image icon of the rich text box, it will open the file selection popup and allow to select only the image file.
- In imageHandler method, we also defined what should be done once the user selects the image from the file selection popup.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
<span class="keyword">public</span> async uploadFiles(uploadFileObj, filename, quillObj) { var libraryName = <span class="string">"ImageFiles"</span>; var context = <span class="keyword">this</span>.props.context; var siteUrl = <span class="keyword">this</span>.props.context.pageContext.site.absoluteUrl; var currentdate = <span class="keyword">new</span> Date(); var fileNamePredecessor = currentdate.getDate().toString() + currentdate.getMonth().toString() + currentdate.getFullYear().toString() + currentdate.getTime().toString(); filename = fileNamePredecessor + filename; <span class="comment">//To Upload in root folder</span> var apiUrl = `${siteUrl}/_api/Web/Lists/getByTitle(<span class="string">'${libraryName}'</span>)/RootFolder/Files/Add(url=<span class="string">'${filename}'</span>, overwrite=<span class="keyword">true</span>)`; <span class="keyword">const</span> digestCache: IDigestCache = <span class="keyword">this</span>.props.context.serviceScope.consume(DigestCache.serviceKey); digestCache.fetchDigest( <span class="keyword">this</span>.props.context.pageContext.web.serverRelativeUrl) .then(async (digest: <span class="keyword">string</span>): Promise<<span class="keyword">void</span>> => { <span class="keyword">try</span> { <span class="keyword">if</span> (uploadFileObj != <span class="string">''</span>) { fetch(apiUrl, { method: <span class="string">'POST'</span>, headers: { <span class="string">'Content-Type'</span>: <span class="string">'application/json;odata=verbose'</span>, <span class="string">"X-RequestDigest"</span>: digest }, body: uploadFileObj <span class="comment">// This is your file object</span> }).then((response) => { console.log(response); <span class="keyword">const</span> range = quillObj.getEditorSelection(); var res = siteUrl + <span class="string">"/"</span> + listName + <span class="string">"/"</span> + filename; quillObj.getEditor().insertEmbed(range.index, <span class="string">'image'</span>, res); }).<span class="keyword">catch</span>((error) => console.log(error) ); } } <span class="keyword">catch</span> (error) { console.log(<span class="string">'uploadFiles : '</span> + error); } }) } |
- quillObj.getEditor().insertEmbed(range.index, ‘image’, res);
- The image will be rendered at the particular place where the cursor’s position using quillObj which we have defined as a global variable and then used while rendering control.
- Now when the user selects the image, it will first be uploaded to the SharePoint document library and then use the uploaded files URL to load the image in the rich text box.
- When you inspect the image in rich text control, you can see the URL of the image, not the base 64 string of the image.
- While saving into the list, when you get the value of rich text control, it will return the image control with the URL of the image. So in the list also it will store the URL of an image.

SharePoint 2013 Hosting – HostForLIFE :: How to Clear Your SharePoint Designer 2010/2013 Cache?
Mar 12th
This is a quick tutorial covering how to clear your SPD 2013 Cache. That is handy, especially when working with SPD 2010 and SPD 2013. Clearing the cache will remove any of your past connection history as well provide you a “clean slate” to work from. The cache is not even cleared after doing a reinstall, so this really is the only way to clear it.
Versioning with check-in/out are great but not always preferred, and certainly not infallible. As I learned on a project a few years ago that recently bit me again when my new machine was not similarly configured, SharePoint Designer has a dirty little habit of caching files, including say the XML/XSLT, JS and CSS you might be working with on your site.
No need to fret though; buried in the settings of each version is a toggle that will ensure SPD never sets you back by loading a cached file.
Procedure:
- Close SPD if it is open
- Open My Computer
a.Click the address bar
- Paste in:
%USERPROFILE%\AppData\Local\Microsoft\WebsiteCache - Delete everything within this location
- Click the address bar
- Paste in:
%APPDATA%\Microsoft\Web Server Extensions\Cache - Delete everything in this location
SharePoint Designer 2010 and 2013
- Navigate to the “File” menu then select “Options” -> “General” -> “Application Options”.
- On the “General” tab, under the “General” heading, uncheck “Cache site data across SharePoint Designer sessions”.