Method to read file or text string to upload files to vault

オフライン

Hi,

I am trying to upload several files to vault by a server side method.

I have created the code below, but gives me error 

Line number -2, Error Number: CS0161, 'PKG_MKTEST_A1_B14858DBCEA85CCE.ItemMethod.methodCode()': not all code paths return a value

I managed to load a single file to the vault  if I define

string filenam1 = "MKDOC13.docx

but if i want to loop  through a list of values to load corresponding file to the vault
(tried values as here in the code and to read separate txt file etc), then 
I get the error above.

Thanks for any help on this

//Mikael

//MY CODE (MKTEST)

var inn = this.newInnovator();

var names = new List<string>() { "MKDOC14.docx", "MKDOC15.docx" };

foreach (string name in names)
{string filenam1 = name;

//string filenam1 = "MKDOC13.docx"; ------- THIS ONE WORK if I remove 'var names...' and the 'for each...' above


string filepath1 = @"C:\Aras\ARAS_Files\"+filenam1;

string format = "Word";
string fileExtension = "docx";

string fileString = filenam1;

// Check-in File to Aras Vault
Item fileItem = inn.newItem("File", "add");
fileItem.setAttribute("doGetItem", "0");
fileItem.setProperty("filename", fileString);
fileItem.attachPhysicalFile(filepath1);
Item checkin_result = fileItem.apply();

// Create new Document
var docItem = inn.newItem("Document","add");
docItem.setAttribute("doGetItem", "0");
string sequenceVal = inn.getNextSequence("Default Document");
docItem.setAttribute("useInputProperties", "1");
docItem.setProperty("item_number", filenam1); //Docnumber
docItem.setProperty("name", fileString ); //DocDescription same as pn
docItem.setProperty("description", "This document was automatically generated.");

// Create new Relationship and attach File
var relItem = inn.newItem("Document File","add");
relItem.setAttribute("doGetItem", "0");
relItem.setProperty("related_id",fileItem.getID());
docItem.addRelationship(relItem) ;
var resultItem = docItem.apply();
if (docItem.isError())
{
return inn.newError("An error occured: " + docItem.getErrorDetail() );
}

var docId = resultItem.getID();
return inn.newResult(docId); // id of new Document

}