This sample script demonstrates how to retrieve files from the file attachment control. The input parameter is the value from the attribute attached to the file attachment control. When “isWithContent” is set to false, it returns only information about the files without loading the file content. This approach avoids impacting the web server’s memory and CPU usage when dealing with large data.

Syntax

List<DmsFile> GetFileFromControl(string groupId, bool isWithContent = true)

public class DmsFile
    {
        public Guid Id { get; set; }
        public string Name { get; set; }
        public string FileContent { get; set; }
        public string FileType { get; set; }
        public Guid FolderId { get; set; }
        public bool IsLockedForCurrentUser { get; set; }
        public string Creator { get; set; }
        public string FilePath { get; set; }
        public int Size { get; set; }
        public short VersionNo { get; set; }
        public FileChangeMode ChangeMode { get; set; }
        public DateTime CreateDate { get; set; }
        public string Description { get; set; }
        public bool IsPublish { get; set; }
    }

Applicability

This functionality is available anywhere users can write C# code.

Code Samples

var file = bpmAppService.BPMSServices.DmsService.GetFileFromControl(domainObject.ExcelFile)[0];
var table = bpmAppService.BPMSServices.DomainObjectService.ReadOfExcel(Convert.FromBase64String(file.FileContent), "Sheet1");

var res = new List<string>();
if (!string.IsNullOrEmpty(domainObject.VendorManualMultiple))
	{
		var files = bpmAppService.BPMSServices.DmsService.GetFileFromControl(domainObject.VendorManualMultiple, false);
		foreach (var f in files)
			res.Add("('" + f.Name + "')");
	}
var pars = string.Join(", ", res);
parameters.Add("q", pars);

if (domainObject.IsVendorManualMultiple.HasValue && domainObject.IsVendorManualMultiple.Value)
	{
		var basePath = System.IO.Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/TempFiles"), "CustomFiles", domainObject.Id.ToString());
		if (System.IO.Directory.Exists(basePath))
			System.IO.Directory.Delete(basePath, true);
		System.IO.Directory.CreateDirectory(basePath);
		if (!string.IsNullOrEmpty(domainObject.VendorManualMultiple))
		{
			var files = bpmAppService.BPMSServices.DmsService.GetFileFromControl(domainObject.VendorManualMultiple);
			foreach (var f in files)
			{
				var fname = System.IO.Path.Combine(basePath, f.Name);
				if (System.IO.File.Exists(fname))
					System.IO.File.Delete(fname);
				System.IO.File.WriteAllBytes(fname, System.Convert.FromBase64String(f.FileContent));
			}
		}
	}