예제 #1
0
        public static void AddLinkToSalesforce(ForceClient forceClient, SharepointFile fileInfo, string url)
        {
            ImageLink__c linkToAdd = new ImageLink__c()
            {
                Name = fileInfo.FileName, Contact__c = fileInfo.ParentId, File_Name__c = fileInfo.FileName, URL__c = url
            };

            // Wait synchronously for the result
            // TODO: maybe offer async option in an overload
            Task <SuccessResponse> response = forceClient.CreateAsync("ImageLink__c", linkToAdd);

            response.Wait();
            SuccessResponse result = response.Result;

            if (result.Success)
            {
                Log("uploaded link successfully to salesforce:\n ID: " + result.Id + " \n filename: " + fileInfo.FileName + " \n ContactID: " + fileInfo.ParentId);
            }
            else
            {
                log.Error("Error inserting link: " + fileInfo.FileName + " for: " + fileInfo.ParentId);
                log.Error(result.Errors.ToString());
                //TODO maybe throw exception
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            try
            {
                // ** Make sure an api key has been entered
                if (API_KEY == string.Empty)
                {
                    Console.WriteLine("[ERROR] Please update the sample code and enter the API Key that came with your subscription.");
                    return;
                }

                // ** Specify the API key associated with your subscription.
                Configuration.Default.AddApiKey("api_key", API_KEY);

                // ** Accept all SSL Certificates, this makes life under mono a lot easier. This line is not needed on Windows
                ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };

                // ** The service's host name is already set, but for debugging purposes you may want to switch between 'http' and 'https'.'
                Configuration.Default.ApiClient.RestClient.BaseUrl = new Uri("https://api.muhimbi.com/api");

                // ** We are dealing with merging, so instantiate the relevant class
                MergeApi mergeApi = new MergeApi();

                // ** Specify details about the SharePoint environment, and the files to merge
                SharepointFile spf = new SharepointFile(
                    SiteUrl: "https://acme.sharepoint.com/sites/SomeSite",                  // ** URL to the site collection, e.g. https://acme.sharepoint.com/sites/SomeSite
                    SourceFileUrl:                                                          // ** List of files to merge including optional ';' separated parameters.
                                                                                            // **   filepath;generate bookmarks (optional);name of bookmark (Optional)
                    @"Shared Documents\SomeFolder\SomeFile.docx;true;My Bookmark
                          Shared Documents\SomeFolder\SomeFile.xlsx;false",
                    DestinationFileUrl: @"Shared Documents\MergedFile.pdf",                 // ** Path and filename to write the results to. See http://goo.gl/YqKXM
                    Username: null,                                                         // ** If the Muhimbi App is installed on the site collection then there is no
                    Password: null                                                          // ** no need to specify credentials. If App is not present, specify login details.
                    );

                // ** Fill out the data for the merge operation.
                MergeToPdfData inputData = new MergeToPdfData(
                    SharepointFile: spf,                                                    // ** Details for the merge operation, see above.
                    SharepointFieldName: "Title",                                           // ** SharePoint field name to use to automatically create a bookmark for each file
                    DocumentStartPage: MergeToPdfData.DocumentStartPageEnum.Nextpage,       // ** On what page should each merged document start (important for double sided docs and printing).
                    SourceFileName1: "",                                                    // ** Mandatory field, so specify empty data
                    SourceFileContent1: new byte[] { 0 },                                   // ** Mandatory field, so specify empty data
                    SourceFileName2: "",                                                    // ** Mandatory field, so specify empty data
                    SourceFileContent2: new byte[] { 0 }                                    // ** Mandatory field, so specify empty data
                    );

                // ** Carry out the merge operation
                Console.WriteLine("[INFO] Merging...");
                var response = mergeApi.MergeToPdf(inputData);

                Console.WriteLine("[INFO] Operation completed - " + response.ResultCode);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
예제 #3
0
 private CourseFile ToCourseFile(SharepointFile file, string courseId)
 {
     return(new CourseFile
     {
         Name = file.Name,
         ServerRelativeUrl = file.ServerRelativeUrl,
         Created = file.TimeCreated,
         LastModified = file.TimeLastModified,
         CourseId = courseId
     });
 }
예제 #4
0
        public static void UploadSalesforceFileToSharepoint(ClientContext ctx, QueryResult <Contact> contact, FileStream fs, SharepointFile fileInfo, List list)
        {
            //build a KVP of RecordTypeId and Text description. Used to set metadata on uploaded file
            var contentArray = RecordTypeArray.Split('|');

            var contentTypeList = new List <KeyValuePair <string, string> >();

            for (int x = 0; x < contentArray.Length; x++)
            {
                var array = contentArray[x].ToString().Split(',');
                contentTypeList.Add(new KeyValuePair <string, string>(array[0], array[1]));
            }

            //Program name = EOC/Talent Search/Upward Bound
            var programName = contentTypeList.First(kvp => kvp.Key == contact.Records[0].RecordTypeId).Value;

            var newFile = new FileCreationInformation();

            //use this method to account for files > 2 MB in size
            newFile.ContentStream = fs;
            newFile.Overwrite     = true;
            newFile.Url           = fileInfo.FileName;

            var contentTypeString = programName + " Document";

            //WHAT IS SHAREPOINT CONTENTTYPE?????????
            ContentType targetContentType = GetContentType(ctx, list, contentTypeString);

            Folder uploadFolder = ctx.Web.GetFolderByServerRelativeUrl(FolderRelativeUrl);

            var uploadFile = uploadFolder.Files.Add(newFile);

            Log("Uploading " + fileInfo.FileName);
            ctx.ExecuteQuery();

            Log("Setting metadata on " + fileInfo.FileName);

            uploadFile.ListItemAllFields.ParseAndSetFieldValue("FirstName", contact.Records[0].FirstName);
            uploadFile.ListItemAllFields.ParseAndSetFieldValue("Last_x0020_Name", contact.Records[0].LastName);
            uploadFile.ListItemAllFields.ParseAndSetFieldValue("Birthday", contact.Records[0].Birthdate.Value.ToShortDateString());
            uploadFile.ListItemAllFields.ParseAndSetFieldValue("ContentTypeId", targetContentType.Id.ToString());
            uploadFile.ListItemAllFields.ParseAndSetFieldValue("Salesforce_x0020_Contact_x0020_ID", fileInfo.ParentId);
            uploadFile.ListItemAllFields.Update();
            ctx.Load(uploadFile);
            ctx.ExecuteQuery();

            Log("Upload of " + fileInfo.FileName + " Complete");
        }