Monday, 27 November 2017

How to read a local text file and sharepoint documents from library (with url of file)


var csvArray = new Array();
var docTitleArray = new Array();
Create a document
function WriteToFile() { debugger; data0 = [[""],["Supplier Business Classifications Interface"], ["Import Action","Supplier Name","Classification","Classification New","Subclassification","Certifying Agency","Certifying Agency New", "Create Certifying Agency","Certificate Number","Certificate Number New","Start Date","Expiration Date","Notes","Provided By First Name", "Provided By Last Name","Provided By E-Mail","Confirmed On"], [" ",supplierName," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "] ]; csvArray.push(data0); docTitleArray.push("SupplierBusinessClassification_"+supplierName+".csv"); data1 = [ ["Import Action","Supplier Name","Supplier Site","Procurement BU","Client BU","Bill-to BU","Ship-to Location", "Bill-to Location"], [" ",supplierName," "," "," "," "," "," "] ]; csvArray.push(data1); docTitleArray.push("SupplierSiteAssignment_"+supplierName+".csv"); data3 = [ ["Import Action","Supplier Name","Procurement BU","Address Name","Supplier Site","Sourcing only","Purchasing", "Procurement card","Pay","Primary Pay","Communication Method","E-Mail","Fax Country Code","Fax Area Code", "Fax","Default Pay Site","Invoice Currency"], [" ",supplierName," ",adr1," "," "," "," "," "," "," ",Email," "," "," "," "," "] ]; csvArray.push(data3); docTitleArray.push("SupplierSite_"+supplierName+".csv"); ATch=0; AttachIT(csvArray[ATch],docTitleArray[ATch]); }
Attach multiple documents in to sharepoint list
function AttachIT(AtachContent,AtachName)
{
debugger;
var CSVcontent="";
    AtachContent.forEach(function(row) {
        CSVcontent += row.join(',');
        CSVcontent += "\n";
    });
      var scriptbase = siteURL + "/_layouts/15/";  
    $.getScript(scriptbase + "SP.RequestExecutor.js", function () {  
        var createitem = new SP.RequestExecutor(_spPageContextInfo.webServerRelativeUrl);  
        createitem.executeAsync({  
            url: siteURL + "/_api/web/lists/GetByTitle('" +vendorList+ "')/items("+currid+")/AttachmentFiles/add(FileName='" + AtachName + "')",  
            method: "POST",  
            binaryStringRequestBody: true,  
            body: CSVcontent,  
            success: fsucc,  
            error: ferr,  
            state: "Update"  
        });  
        function fsucc(data) { 
        debugger;
         ATch++;
         if(ATch<=2){
        AttachIT(csvArray[ATch],docTitleArray[ATch]);
   }
   else{ 
       UpdateWFstatus();
            }
        }  
        function ferr(data) {
        debugger;  
            console.log(AtachName+ "not uploaded error");  
        }  
 }); 
}           



Refer this link
https://stackoverflow.com/questions/14446447/how-to-read-a-local-text-file






function readTextFile(file)
{
    var rawFile = new XMLHttpRequest();
    rawFile.open("GET", file, false);
    rawFile.onreadystatechange = function ()
    {
        if(rawFile.readyState === 4)
        {
            if(rawFile.status === 200 || rawFile.status == 0)
            {
                var allText = rawFile.responseText;
                alert(allText);
            }
        }
    }
    rawFile.send(null);
}

No comments:

Post a Comment

How to get the value from web.config(if any value assign as static Key)

Web.Config File:   <appSettings>     <add key="DomainName" value="PW" />     </appSettings> Cl...