If you're looking for a snippet to create a File item and to upload a file object within PI, then this snippet will provide you with a good starting point.


//create new file item
ProjectInsight.Models.Files.FileItem myFile = new ProjectInsight.Models.Files.FileItem();
myFile.ItemContainer_Id = "[[ITEM_CONTAINTER_GUID]]";
myFile.Name = "Testing New File";

//create FileUpload object for file item
ProjectInsight.Models.Files.FileUpload fileUpload = new ProjectInsight.Models.Files.FileUpload();
fileUpload.FileName = "Test Upload File";
fileUpload.FileContentsBase64Encoded = "[[Base64 Encoded String]]"; //Content of the file to upload
myFile.UploadedFile = fileUpload;

//Save and return a response
ProjectInsight.Models.Base.Responses.ApiSaveResponse saveFileResp = new ProjectInsight.Models.Base.Responses.ApiSaveResponse();
saveFileResp = this.client.FileItem.Save(myFile);


Download a file

This snippet is intended for users who'd like to download files.

	
     
//Retrieve the FileItem to use properties
FileItem file = this.client.FileItem.Get(fileId);

//Send a response to try and download the file
HttpResponseMessage resp = this.client.FileItem.Download(file.Id.Value);

byte[] bytes = resp.Content.ReadAsByteArrayAsync().Result;

FileStream wFile = new FileStream("c:\\Temp\\" + file.FileName.ToString(), FileMode.Create);
wFile.Write(bytes, 0, bytes.Length);
wFile.Close();     
     
Online 1/23/2017