Auto Downloading ECM Attachments

I had a requirement to alert shipping when they have a part with specific, custom packaging requirements. I suggested that we could do better, actually give them the instructions if they need them so they didn’t have to look them up.

I added Packing Instructions (“PartPack”) as a document type on the part master. The method below just looks for the presence of such items and prompts the user to this requirement, as well as offer to retrieve them.

private void GetPackagingInstructions(string partNum)
	using (var partAdapter = new Erp.Adapters.PartAdapter(oTrans))
		DataView PartAttch = partAdapter.PartData.PartAttch.AsDataView();
		DataRow[] partPacks = partAdapter.PartData.PartAttch.Select("DocTypeID = 'PartPack'");

		if (partPacks.Length > 0)
			var dialog = MessageBox.Show(
				"This part has special packaging requirements. Would you like to view the instructions?" +
					"\n \nIf you decline or close the instructions, you may look them up at any time in Part Tracker",
			if (dialog == DialogResult.Yes)
				var session = (Ice.Core.Session)oTrans.Session;
				string uri = Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.AttachmentSvcContract>.UriPath;
				using (var attachmentBo = WCFServiceSupport.CreateImpl<Ice.Proxy.BO.AttachmentImpl>(session, uri))
					foreach (var row in partPacks)
						int xFileRefNum = (int)row[partAdapter.PartData.PartAttch.XFileRefNumColumn.ColumnName];
						string xFileName = (string)row[partAdapter.PartData.PartAttch.FileNameColumn.ColumnName];
						string xFileExt = xFileName.Substring(xFileName.Length - 4);
						var metaData = new Dictionary<string, string>();

						byte[] fileData = attachmentBo.DocStarDownloadFile(xFileRefNum, ref metaData);
						string fileName = System.IO.Path.GetTempFileName().Replace(".tmp", xFileExt);
						File.WriteAllBytes(fileName, fileData);

Shoutout to @Moe and @josecgomez There were a couple of pieces that they covered in this topic that saved me a lot of googling: