/// <summary> /// Add a file to the package. /// </summary> /// <param name="filePath">The full path of the file to be added. E.g. "D:\files\template.rtf".</param> /// <param name="internalName">The name within the package. E.g. "template.rtf" or "images/icon.png".</param> /// <returns>The internal name used. E.g. "template.rtf" or "images/icon.png". This name can be used to be shown to the user and can be used to extract a file again.</returns> public string AddFile(string filePath, string internalName) { Uri partUri; PackagePart packagePart = null; // CondCreateStream(); try { using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { partUri = InternalNameToPartUri(internalName); packagePart = _package.CreatePart(partUri, Util.GetMimeType(filePath), _compression); using (Stream ps = packagePart.GetStream(FileMode.Create, FileAccess.ReadWrite)) { CopyStream(ps, fs); } } } catch (IOException ex) { System.Diagnostics.Debug.WriteLine("TemplatePackage.AddFile Exception thrown: " + ex); throw; } if (packagePart != null) { return(PartUriToInternalName(packagePart.Uri)); } else { return(null); } }
/// <summary> /// This is called repeatedly by the interview JS to retrieve the files needed for the interview /// </summary> /// <returns></returns> public FileStreamResult GetInterviewFile() { //File name of template or image var fileName = Request.QueryString["template"]; //Template location var templateLocationData = Request.QueryString["loc"]; var templateLocation = Template.Locate(templateLocationData); //Type of file requested var fileType = Request.QueryString["type"]; fileType = fileType.ToLower(); //Get interview stream var service = CreateHotDocsService(); var interviewFileStream = service.GetInterviewFile(templateLocation, fileName, fileType); //Get MIME type var outputFileName = fileType == "img" ? fileName : fileName + "." + fileType; var interviewResultMimeType = Util.GetMimeType(outputFileName, fileType == "img"); var interviewFileStreamResult = new FileStreamResult(interviewFileStream, interviewResultMimeType); return(interviewFileStreamResult); }
private void SaveManifest() { Uri partUri = InternalNameToPartUri(ManifestName); PackagePart packagePart; string errMsg; if (!IsValidManifest(out errMsg)) { throw new Exception("Invalid manifest: " + errMsg); } if (_package.PartExists(partUri)) { packagePart = _package.GetPart(partUri); } else { packagePart = _package.CreatePart(partUri, Util.GetMimeType(ManifestName), _compression); } using (Stream ps = packagePart.GetStream(FileMode.Create, FileAccess.ReadWrite)) { _manifest.ToStream(ps); } }