using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; using System.Reflection; class Program { static void Main() { { string boundary = "abc_" + DateTime.UtcNow.ToString("yyyy-MM-dd-HH-mm-ss-fff") + "_xyz"; string strExeFilePath = Assembly.GetExecutingAssembly().Location; string startupPath = Path.GetDirectoryName(strExeFilePath); string outputPath = Path.Combine(startupPath, boundary); Console.OutputEncoding = System.Text.Encoding.Unicode; Console.InputEncoding = System.Text.Encoding.Unicode; //PDM vault destination Console.WriteLine("Enter the destination folder path in your PDM vault that begins backslash(\\) where file(s) should be uploaded"); Console.WriteLine("Or enter PDM vault root path - backslash(\\) symbol. Do not provide the full path name of the local view folder"); string folderPath = Console.ReadLine(); if (folderPath.Contains(":")) { Console.WriteLine("Error: The path contains the colon(:) symbol. Exiting program. Please provide PDM vault's path instead of the full path of the local view folder. Enter backslash(\\) if the PDM vault's root path"); Environment.Exit(1); } //List of files to be uploaded Console.WriteLine("Enter the file path(s) (separated by semicolon if more than one). Do not wrap paths in double quotes:"); string filesInput = Console.ReadLine(); if (filesInput.Contains("\"")) { Console.WriteLine("Error: The file path(s) contains the double quote(\") symbol. Exiting program. Please provide the semicolon delimited file paths without wrapping them in double quotes"); Environment.Exit(1); } List files = filesInput.Split(';').Select(file => file.Trim()).ToList(); // Call the method to generate the binary file GenerateBinaryFile(folderPath, files, outputPath, boundary); Console.WriteLine($"Now you can upload the binary file(s) to your PDM vault"); Console.WriteLine($"Step 1: Attach the just generated output file to the binary Body of your Postman HTTP request"); Console.WriteLine($"Step 2: Replace the Postman HTTP request Header 'Content-Type' with this value:"); Console.WriteLine($" multipart/form-data; boundary=\"{boundary}\""); Console.WriteLine($"Step 3: Modify other items in your Postman HTTP request (i.e. Bearer token, Headers, etc) and send request"); Console.WriteLine(" Press any key to exit..."); Console.ReadKey(); } } public static void GenerateBinaryFile(string folderPath, List files, string outputPath, string boundary) { using (var content = new MultipartFormDataContent(boundary)) { foreach (var file in files) { if (!File.Exists(file)) { Console.WriteLine($"Error: File '{file}' does not exist. Exiting program."); Environment.Exit(1); } var fileContent = CreateFileContent(file, folderPath); content.Add(fileContent); } // Save the binary content to a file var binaryContent = content.ReadAsByteArrayAsync().Result; File.WriteAllBytes(outputPath, binaryContent); Console.WriteLine($"Binary content saved to '{outputPath}' file"); Console.WriteLine(""); } } private static MultipartFormDataContent CreateFileContent(string file, string folderPath) { var content = new MultipartFormDataContent { new FormUrlEncodedContent(new List>(3) { new KeyValuePair("CreationDate", System.IO.File.GetCreationTimeUtc(file).ToString("O")), new KeyValuePair("ModificationDate", System.IO.File.GetLastWriteTimeUtc(file).ToString("O")), new KeyValuePair("PathInVault", $"{folderPath}") }) }; var streamContent = new StreamContent(System.IO.File.OpenRead(file)); content.Add(streamContent, "file", file); return content; } }