Posts

Query String Builder V1

public static string BuildUrlWithQueryString ( string baseUrl, NameValueCollection parameters ) { var queryString = string .Join( "&" , parameters.AllKeys .Select(key => string .IsNullOrEmpty(parameters[key]) ? HttpUtility.UrlEncode(key) : $" {HttpUtility.UrlEncode(key)} = {HttpUtility.UrlEncode(parameters[key])} " )); return string .IsNullOrEmpty(queryString) ? baseUrl : $" {baseUrl} ? {queryString} " ; }
 <script type="text/javascript"> function uploadFileAsAttachment(itemId, fileInput) {   var file = fileInput.files[0];      if (file) {     var context = SP.ClientContext.get_current();     var web = context.get_web();     var list = web.get_lists().getByTitle("Your List Name");     var listItem = list.getItemById(itemId);          // Read the file data     var reader = new FileReader();          reader.onloadend = function (evt) {       if (evt.target.readyState == FileReader.DONE) {         // Create a new file creation information object         var attachmentInfo = new SP.AttachmentCreationInformation();         attachmentInfo.set_contentType(file.type);         attachmentInfo.set_fileName(file.name);         attachmentInfo.set_attachmentContent(new SP.Base64EncodedByteArray());                  // Convert the file data to byte array         var byteArray = new Uint8Array(evt.target.result);                  for (var i = 0; i < byteArray.byteLength; i++
 <script type="text/javascript"> function uploadFile() {   var fileInput = document.getElementById("fileInput");   var file = fileInput.files[0];      if (file) {     var context = SP.ClientContext.get_current();     var web = context.get_web();     var list = web.get_lists().getByTitle("Your List Name");     var folder = list.get_rootFolder();          context.load(folder);          // Read the file data     var reader = new FileReader();          reader.onloadend = function (evt) {       if (evt.target.readyState == FileReader.DONE) {         // Create a new file creation information object         var fileInfo = new SP.FileCreationInformation();         fileInfo.set_url(file.name);         fileInfo.set_content(new SP.Base64EncodedByteArray());                  // Convert the file data to byte array         var byteArray = new Uint8Array(evt.target.result);                  for (var i = 0; i < byteArray.byteLength; i++) {           fileInfo.get_

Sample HTML

 <!DOCTYPE html> <html> <head>   <title>SharePoint Layout with Glassy Look</title>   <style>     body {       background-color: #800000; /* Maroon background color */       color: #FFFFFF; /* White text color */       font-family: Arial, sans-serif;       margin: 0;       padding: 0;     }     .container {       max-width: 960px;       margin: 0 auto;       padding: 20px;       background-color: rgba(255, 255, 255, 0.8); /* Semi-transparent white background */       box-shadow: 0 0 10px rgba(0, 0, 0, 0.3); /* Glassy box shadow */     }     h1, h2, h3 {       margin: 0;     }     .content {       margin-top: 20px;     }   </style> </head> <body>   <div class="container">     <h1>Welcome to SharePoint</h1>     <div class="content">       <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>       <p>Donec at dapibus nisi. Vestibulum cursus dui vel fringilla conseq

Retrieve List Item Details

 function retrieveListItemDetails(listName, itemId) {   // Get the current SharePoint context   var context = SP.ClientContext.get_current();   // Get the list   var list = context.get_web().get_lists().getByTitle(listName);   // Get the list item   var listItem = list.getItemById(itemId);   // Load the list item properties   context.load(listItem);   // Execute the query   context.executeQueryAsync(     function () {       // On success, retrieve the item values       var title = listItem.get_item('Title');       var description = listItem.get_item('Description');       // Concatenate the values into a query string parameter       var queryStringParam = 'title=' + encodeURIComponent(title) +         '&description=' + encodeURIComponent(description);       // Pass the query string parameter to another application or redirect       // Example: window.location.href = 'https://example.com/otherapp?' + queryStringParam;       // Log the query str

Javascript function to populate from query string

 function populateFieldsFromQueryString() {   // Get the query string from the URL   const queryString = window.location.search;   // Check if there is a query string   if (queryString) {     // Remove the leading "?" character     const queryParams = queryString.substring(1);     // Split the query string into key-value pairs     const keyValuePairs = queryParams.split("&");     // Loop through the key-value pairs     keyValuePairs.forEach((pair) => {       // Split each pair into key and value       const [key, value] = pair.split("=");       // Decode the key and value (in case of URL encoding)       const decodedKey = decodeURIComponent(key);       const decodedValue = decodeURIComponent(value);       // Find the corresponding field in the document       const field = document.querySelector(`[name="${decodedKey}"]`);       // Check if the field exists       if (field) {         // Populate the field with the value         field.value =
 Concat(     GroupBy(         'CollectionName',         "IdentityColumn",         "GroupedData",         "NameColumn"     ),     If(         CountRows("GroupedData") = 1,         "GroupedData[@NameColumn]",         Concatenate(             "GroupedData[@NameColumn]",             ", ",             "GroupedData[@NameColumn]",             GroupedData,             ", "         )     ),     " " )