Kashif Nizam Qureshi


Leave a comment

Upload Document From PDP to Project Site


<input id="inputFile" type="file"/><input id="uploadDocumentButton" onclick="uploadFile()" type="Button" value="Upload Document"/><script src="/PWA/SiteAssets/jquery.min.js"></script><script type="text/javascript">
//Function attached to the html fileupload tag (<input type="file">)
function uploadFile(){
    if (document.getElementById("inputFile").files.length === 0) {
        alert('No file was selected');
        return;
    }
    var parts = document.getElementById("inputFile").value.split("\\");
    var ExtPart = document.getElementById("inputFile").value.split('.').pop();
        
    var filename = "NYUAD-PMO_" + PDP_projName + "_Project Charter-Template_v1_0." + ExtPart;
    var file = document.getElementById("inputFile").files[0];
      var getUrl = "http://sps2013/PWA/" + PDP_projName;
    uploadFileSync(getUrl , "Documents", filename, file);
}

//Upload file synchronously
function uploadFileSync(spWebUrl , library, filename, file) 
{
        var reader = new FileReader();
    reader.onloadend = function(evt) 
    {
      if (evt.target.readyState == FileReader.DONE) 
      {
         var buffer = evt.target.result;
         // To upload files to root folder
         //var completeUrl = spWebUrl
         //  + "/_api/web/lists/getByTitle('"+  library + "')"
         //  + "/RootFolder/Files/add(url='"+ filename +"',overwrite='true')?"
         //  + "@TargetLibrary='"+ library +"'&@TargetFileName='"+ filename +"'";
         
         // To upload files to sub-folder
         var completeUrl = spWebUrl
           + "/_api/web/lists/getByTitle('"+  library + "')"
           + "/RootFolder/Folders('Initiation%20Phase')/Folders('PCID')/Files/add(url='"+ filename+"',overwrite='true')?"
           + "@TargetLibrary='"+ library +"'&@TargetFileName='"+ filename +"'";           

          $.ajax({
                url: completeUrl,
                type: "POST",
                data: buffer,
                async: false,
                processData: false,
                headers: {
                    "accept": "application/json;odata=verbose",
                    "X-RequestDigest": $("#__REQUESTDIGEST").val(),
                    "content-length": buffer.byteLength
                },
                complete: function (data) {
                    alert('succes');
                },
                error: function (err) {
                     alert('failed');
                }
        });
      }
    };
    reader.readAsArrayBuffer(file);
}
</script> 


Leave a comment

Querying Projects Document from Site and Displaying them in PDP

<div id="LeftNavForMySite">
   <table width="400">
      <tbody>
         <tr>
            <td>File Name</td>
            <td> Last Modified</td>
         </tr>
         <tr>
            <td>
               <a href="/PWA/Application%20Project/Shared%20Documents/Initiation/general.css">general.css</a></td>
            <td>2016-07-03 21:23 </td>
         </tr>
      </tbody>
   </table>
</div>
<script type="text/javascript">
 
//We need to run our function only after sp.js file loads
ExecuteOrDelayUntilScriptLoaded(ViewItem, "sp.js");
 
 
function ViewItem()
{
 var projuid=  PDP_projUid;
 var url="/PWA/"+ PDP_projName;
   
var context = new SP.ClientContext(url);
  
var web = context.get_web();

var list = web.get_lists().getByTitle('Documents');
 
//CamlQuery()
//For querying Nth level within the library
//var query = SP.CamlQuery.createAllItemsQuery();

//For querying to current library or folder if defined below
var query = new SP.CamlQuery();

//Leading forward slash was the pain in the ass in the below line
//Folder structure starts with library name and follows folder names.
query.set_folderServerRelativeUrl('Shared%20Documents/Initiation');

allItems = list.getItems(query);
context.load(allItems, 'Include(Title, ContentType, File, Modified, FileSystemObjectType)');
context.executeQueryAsync(Function.createDelegate(this, this.success),   Function.createDelegate(this, this.failed));
}
 
function success()
{
 //alert('s');
 var table='<table width="400"><tr><td>File Name</td><td> Last Modified</td>';
 var modified="";
  var fileUrls = "";
  var ListEnumerator = this.allItems.getEnumerator();
   while(ListEnumerator.moveNext())
   {
// alert('d');
    var currentItem = ListEnumerator.get_current();
    
   //if(currentItem.get_fileSystemObjectType() == '1')
   //{
   //   alert(currentItem.get_item('Title'));
   
      
     var _contentType = currentItem.get_contentType();
     if(_contentType.get_name() != "Folder")
       {
        var File = currentItem.get_file();
        if(File != null)
          {
          //alert(currentItem.get_item('Modified'));
          modified=String.format("{0:yyyy}-{0:MM}-{0:dd} {0:HH}:{0:mm} ",new Date(currentItem.get_item('Modified')));
          fileUrls += File.get_serverRelativeUrl() + '\n';
           table=table+'<tr>';
            table=table+('<td><a href="'+fileUrls+'">'+File.get_name()+'</a></td><td>'+modified+'</td></tr>');
          }
       }
    //}
  }
  
         //Getting the empty div tag
         fieldNameElement=document.getElementById('LeftNavForMySite');
 
         //Assign the string formed to the div element's innerHTMl to display on page
         fieldNameElement.innerHTML=table+"</table>";
 }
 function failed(sender, args) {
  alert("failed. Message:" + args.get_message());
 }
  
</script> 


Leave a comment

PDP to List data entry

Place jquery file as per location.

Add the following in a add form of list item, replacing ProjUID and Owning Project with the correct column name.

<script src="/PWA/SiteAssets/jquery-1.10.2.min.js" type="text/javascript"></script><script type="text/javascript">
$(document).ready(function() {

 var Puid = window.parent.PDP_projUid;
 var project_name = window.parent.PDP_projName; 

  
 var subjectIDTextField1 = getElementByTitle("input","ProjUID");
 subjectIDTextField1.value = Puid; 

 var subjectIDTextField= getElementByTitle("input","Owning Project");
 subjectIDTextField.value = project_name; 
  
 $(":input[title='Owning Project']").attr('disabled','disabled');

var HidePUID = getElementByTitle("input","ProjUID");
                $(HidePUID).closest("tr").hide();

 });
 
function getElementByTitle(tagName,elementTitle)
{
	var list = document.getElementsByTagName(tagName);
	var elementTag;
	for (i=0;i!=list.length;i++) {
	if (list[i].title == elementTitle) {
	elementTag = list[i];
	return elementTag;
	}
	}
}
    
 </script>​​​​

Add the list on a PDP and add content query filter to filter the list on projuid.


Leave a comment

Adding Link in Project Detail Page (PDP) to Project Site List

To add a link in PDP that will navigate to Project Site List, add the following script in a content editor.


<p>
<a href="/PWA/SiteAssets/jquery-1.10.2.min.js">/PWA/SiteAssets/jquery-1.10.2.min.js</a>

function proj1() {

var projuid= PDP_projUid;
var url="/PWA/"+ PDP_projName +"/_layouts/15/start.aspx#/Lists/Assumptions%20and%20Constraints/AllItems.aspx";

window.open(url,'_blank');
}
<a href="javascript:proj1();">Click here to Enter and Preview Assumptions and Constraints Details </a></p>

//var $j = jQuery.noConflict();
//function getParameterByName(name) {
//name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
//var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
//results = regex.exec(location.search);
//return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
//}

<p>
</p>


Leave a comment

Configuring Apps for SharePoint 2013

Follow the steps to configuring Apps for SharePoint 2013

  1. Create Domain (Forward Lookup Zone) example apps.systemsltd.local #Sourceapp
  2. Configure App URL #Source
    appsurl
  3. Manage App Catalog
    Here you’ll be creating site for Appsmanage app catalog
  4. Now you’ll be able to add an app. Make sure you’re not logged in as System Account and the user who is adding App from App Store is in Local Administrator account (without it I was having error).
Follow

Get every new post delivered to your Inbox.