Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: updated example code

...

Code Block
languagec#
titleCreate Document File Attachment
linenumberstrue
/* IMPORTANT!
** For using this example you need to uncheck the "Allow generation of asynchronous operation" option in advanced Service Reference settings*/

using System;
using System.Data;
using System.IO;
using YourServiceReferenceHere;

namespace ConsoleApp2
{
    class Program
    {
        public static SecurityToken GetAuth()
        {
            SecurityToken securityToken = new SecurityToken()
            {
                Username = "Student Portal",
                UserId = -2,
                DashboardAdmin = true
            };

            return securityToken;
        }
        static void Main(string[] args)
        {
            string filePath = /*File path here*/"C:\\Users\\katie.macpherson\\Downloads\\test.txt";
            int documentRequirementId = /*ID here*/123456;
            stringint mimeTypestudentId = "text/plain";//Example4996;

            CreateDocumentFileAttachment(documentRequirementId, filePath, mimeType, studentId);

        }
        static void CreateDocumentFileAttachment(int documentRequirementId, string filePath, string mimeType, int studentId)
        {
            using (var client = new RegentEnterpriseServiceClient())
            {
                var file = new FileInfo(filePath);
                var record = new DocumentRequirementFileAttachment()
                {
                    DocumentRequirementId = documentRequirementId,
                    DocumentRequirementIdSpecified = true,
                    FileName = file.Name,
                    FileSize = file.Length,
                    FileSizeSpecified = true,
                    MimeType = mimeType,                    
StoredFileName = $"{Guid.NewGuid()}.{Path.GetExtension(filePath)}",
                    StoredFile = File.ReadAllBytes(file.FullName),                     CreatedBy = -168,                     CreatedBySpecified = true,
                    isFileExists = false,
                    isFileExistsSpecified = true,
                    CreatedOn = DateTime.Now,
                    CreatedOnSpecified = true,
                    ModifiedOn = DateTime.Now,
                    ModifiedOnSpecified = true,                   
   ModifiedBy = -168,
              };

                var ModifiedBySpecifiedcreateDocumentAttachmentRequest = true,new UpdateDocumentRequirementFileAttachmentRequest
                {
};                   var createDocumentAttachmentRequestRecord = new UpdateDocumentRequirementFileAttachmentRequestrecord,
                    StudentId = {studentId,
                    RecordStudentIdSpecified = recordtrue,
                    SecurityToken = GetAuth(),
                };
                var response = client.createDocumentRequirementFileAttachment(createDocumentAttachmentRequest);

                if (response.ErrorYN)
                {
                    throw new Exception(response.Message);
                }
            }
        }
	}
}

...