protected AttachmentLink IsInlineImage(HtmlTagContextAttribute filterAttribute) { AttachmentLink attachmentLink = this.IsInlineReference(filterAttribute.Value); if (attachmentLink != null) { string text; if (attachmentLink.AttachmentType == AttachmentType.Ole) { text = "image/jpeg"; } else { text = attachmentLink.ContentType; if (string.Compare(text, "image/tiff", StringComparison.OrdinalIgnoreCase) == 0) { return(null); } } if (text.StartsWith("image/", StringComparison.OrdinalIgnoreCase)) { this.hasInlineImages = true; return(attachmentLink); } } return(null); }
private string GetInlineReferenceUrl(AttachmentPolicy.Level level, AttachmentLink imageAttachmentLink, HtmlWriter writer) { imageAttachmentLink.MarkInline(true); if (AttachmentPolicy.Level.Allow == level) { StringBuilder stringBuilder = new StringBuilder(); if (this.isEmbeddedItem) { stringBuilder.Append(this.embeddedItemUrl); } else { stringBuilder.Append(OwaSafeHtmlCallbackBase.AttachmentBaseUrl); bool flag = this.owaStoreObjectIdType == OwaStoreObjectIdType.OtherUserMailboxObject || this.owaStoreObjectIdType == OwaStoreObjectIdType.ArchiveMailboxObject; OwaStoreObjectId owaStoreObjectId = OwaStoreObjectId.CreateFromItemId(this.itemId, flag ? null : this.parentId, this.owaStoreObjectIdType, this.legacyDN); stringBuilder.Append(Utilities.UrlEncode(owaStoreObjectId.ToString())); stringBuilder.Append("&attcnt=1&attid0="); } stringBuilder.Append(Utilities.UrlEncode(imageAttachmentLink.AttachmentId.ToBase64String())); if (!this.isEmbeddedItem && !string.IsNullOrEmpty(imageAttachmentLink.ContentId)) { stringBuilder.Append("&attcid0="); stringBuilder.Append(Utilities.UrlEncode(imageAttachmentLink.ContentId)); } return(stringBuilder.ToString()); } this.hasBlockedImagesInCurrentPass = true; this.hasBlockedInlineAttachments = true; return(OwaSafeHtmlOutboundCallbacks.BlockedUrlPageValue); }
public ActionResult FileUpload(FormCollection formCollection) { using (BTCEntities db = new BTCEntities()) { string attachmentsForVal = "Unknown", retrunToVal = "Index"; string IDVal = ""; int QuoteID = Convert.ToInt32(formCollection["QuotationID"]); int ID = Convert.ToInt32(formCollection["ID"]); if (Request.Files != null && Request.Files.Count > 0) { string fileName = string.Empty; string destinationPath = string.Empty; List <Attachments> uploadFileModel = new List <Attachments>(); SetQuotation(pageNo, ID, out attachmentsForVal, out IDVal, out retrunToVal); fileName = Path.GetFileName(Request.Files[0].FileName); destinationPath = Path.Combine(Server.MapPath("~/UploadedFiles/" + attachmentsForVal) + "/", fileName); Directory.CreateDirectory(Server.MapPath("~/UploadedFiles/" + attachmentsForVal)); Request.Files[0].SaveAs(destinationPath); var isFileNameRepete = (db.Attachments.AsEnumerable().Where(x => x.FileName == fileName).ToList()); if (isFileNameRepete == null || isFileNameRepete.Count <= 0) { Attachments attachments = new Attachments { FileName = fileName, FileType = Request.Files[0].ContentType, FilePath = destinationPath, UploadedDate = DateTime.Now, UploadedBy = dbuser.ID }; db.Attachments.Add(attachments); db.SaveChanges(); AttachmentLink attachmentLink = new AttachmentLink { AttachmentFor = attachmentsForVal, AttachmentForID = attachments.ID }; db.AttachmentLink.Add(attachmentLink); db.SaveChanges(); ViewBag.SuccessMessage = "File Uploaded Successfully"; } else { ViewBag.WarningMessage = "File is already exists"; } } ViewBag.fileUploader = db.AttachmentLink.Where(a => a.AttachmentFor.Contains(attachmentsForVal)).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); switch (pageNo) { case 1: return(RedirectToAction(retrunToVal, new { QuoteID, atquoteID = ID })); case 2: return(RedirectToAction(retrunToVal, new { QuoteID, hsquoteID = ID })); case 3: return(RedirectToAction(retrunToVal, new { QuoteID, pcquoteID = ID })); default: return(RedirectToAction(retrunToVal, new { QuoteID })); } } }
private string GetOrGenerateAttachContentId(AttachmentLink attachmentLink) { StoreObjectId key = this.itemId; if (this.existingContentIds == null && !Command.CurrentCommand.InlineAttachmentContentIdLookUp.TryGetValue(key, out this.existingContentIds)) { this.existingContentIds = new Dictionary <AttachmentId, string>(1); Command.CurrentCommand.InlineAttachmentContentIdLookUp[key] = this.existingContentIds; } string text; if (this.existingContentIds.TryGetValue(attachmentLink.AttachmentId, out text) && !string.IsNullOrEmpty(text)) { attachmentLink.ContentId = text; } else { if (string.IsNullOrEmpty(attachmentLink.ContentId)) { attachmentLink.ContentId = Guid.NewGuid().ToString(); } this.existingContentIds[attachmentLink.AttachmentId] = attachmentLink.ContentId; } attachmentLink.MarkInline(true); return(attachmentLink.ContentId); }
private void MarkInlineAttachment(string srcValue) { string contentId = HtmlUpdateBodyCallback.GetContentId(srcValue); if (contentId == null) { ExTraceGlobals.CommonAlgorithmTracer.TraceDebug <string>((long)this.GetHashCode(), "HtmlUpdateBodyCallback.MarkInlineAttachment. Content ID is empty for {0}", srcValue); return; } AttachmentId attachmentId = this.FindAttachmentId(contentId); if (attachmentId == null) { ExTraceGlobals.CommonAlgorithmTracer.TraceDebug <string>((long)this.GetHashCode(), "HtmlUpdateBodyCallback.MarkInlineAttachment. Attachment ID not found for {0}", srcValue); return; } AttachmentLink attachmentLink = base.FindAttachmentByIdOrContentId(attachmentId, contentId); if (attachmentLink == null) { ExTraceGlobals.CommonAlgorithmTracer.TraceDebug <string>((long)this.GetHashCode(), "HtmlUpdateBodyCallback.MarkInlineAttachment. No attachment link found for {0}", srcValue); return; } attachmentLink.MarkInline(true); }
protected void ProcessHtmlUrlTag(HtmlTagContextAttribute filterAttribute, HtmlWriter writer) { string value = filterAttribute.Value; AttachmentLink attachmentLink = this.IsInlineReference(value); if (attachmentLink != null) { this.OutputInlineReference(filterAttribute, attachmentLink, writer); return; } SafeHtmlCallback.TypeOfUrl typeOfUrl = SafeHtmlCallback.GetTypeOfUrl(filterAttribute.Value, filterAttribute.Id); if (typeOfUrl == SafeHtmlCallback.TypeOfUrl.Redirection) { filterAttribute.Write(); this.hasFoundRedirUrlInCurrentPass = true; return; } if (typeOfUrl == SafeHtmlCallback.TypeOfUrl.Trusted || typeOfUrl == SafeHtmlCallback.TypeOfUrl.Local) { filterAttribute.Write(); return; } if (typeOfUrl == SafeHtmlCallback.TypeOfUrl.Unknown) { writer.WriteAttribute(filterAttribute.Id, " "); } }
public static AttachmentPolicy.Level GetAttachmentLevel(AttachmentLink attachmentLink, UserContext userContext) { if (attachmentLink == null) { throw new ArgumentNullException("attachmentLink"); } return(AttachmentLevelLookup.GetAttachmentLevel(attachmentLink.AttachmentType, attachmentLink.FileExtension, attachmentLink.ContentType, userContext)); }
protected AttachmentPolicy.Level GetAttachmentLevel(AttachmentLink link) { if (link.AttachmentType == AttachmentType.Stream || link.AttachmentType == AttachmentType.Ole) { this.isembeddedItem = true; return(AttachmentPolicy.Level.Allow); } return(AttachmentPolicy.Level.Block); }
protected string GetContentType(AttachmentLink link) { if (link.AttachmentType == AttachmentType.Ole) { link.ConvertToImage(); return("image/jpeg"); } return(link.ContentType); }
protected void GetAttachmentLinkAndLinkSource(HtmlTagContext tagContext, out AttachmentLink link, out string srcValue) { link = null; srcValue = (from attr in tagContext.Attributes where attr.Id == HtmlAttributeId.Src select attr.Value).FirstOrDefault <string>(); if (!string.IsNullOrEmpty(srcValue)) { link = base.FindAttachmentByBodyReference(srcValue); } }
protected AttachmentPolicy.Level GetAttachmentLevel(AttachmentLink attachmentLink) { if (this.isJunkOrPhishing) { return(AttachmentPolicy.Level.Block); } if (attachmentLink.AttachmentType == AttachmentType.EmbeddedMessage) { return(AttachmentPolicy.Level.Block); } return(AttachmentLevelLookup.GetAttachmentLevel(attachmentLink, this.owaContext.UserContext)); }
// Token: 0x060010C4 RID: 4292 RVA: 0x00066E38 File Offset: 0x00065038 protected override void ProcessImageTag(HtmlTagContextAttribute filterAttribute, HtmlTagContext context, HtmlWriter writer) { AttachmentLink attachmentLink = base.IsInlineImage(filterAttribute); if (attachmentLink != null) { base.OutputInlineReference(filterAttribute, context, attachmentLink, writer); return; } if (base.IsSafeUrl(filterAttribute.Value, filterAttribute.Id)) { filterAttribute.Write(); } }
protected void ProcessImageTag(HtmlTagContextAttribute filterAttribute, HtmlTagContext context, HtmlWriter writer) { AirSyncDiagnostics.Assert(context != null); string value = filterAttribute.Value; AttachmentLink attachmentLink = this.IsInlineReference(value); if (attachmentLink != null) { this.OutputInlineReference(filterAttribute, attachmentLink, writer); return; } if (SafeHtmlCallback.IsSafeUrl(filterAttribute.Value, filterAttribute.Id)) { filterAttribute.Write(); } }
protected virtual void ProcessImageTag(HtmlTagContextAttribute filterAttribute, HtmlTagContext context, HtmlWriter writer) { AttachmentLink attachmentLink = this.IsInlineImage(filterAttribute); if (attachmentLink != null) { this.OutputInlineReference(filterAttribute, context, attachmentLink, writer); return; } if (this.IsSafeUrl(filterAttribute.Value, filterAttribute.Id)) { this.hasBlockedImagesInCurrentPass = true; this.hasBlockedImages = true; writer.WriteAttribute(filterAttribute.Id, OwaSafeHtmlCallbackBase.blankImageFileName); } }
protected override void ProcessImageTag(HtmlTagContextAttribute filterAttribute, HtmlTagContext context, HtmlWriter writer) { AttachmentLink attachmentLink = base.IsInlineImage(filterAttribute); if (attachmentLink != null) { base.OutputInlineReference(filterAttribute, context, attachmentLink, writer); return; } if (base.IsSafeUrl(filterAttribute.Value, filterAttribute.Id)) { this.hasBlockedImagesInCurrentPass = true; this.hasBlockedImages = true; string value = this.owaContext.UserContext.GetBlankPage(Utilities.PremiumScriptPath) + "#" + OwaSafeHtmlConversationsCallbacks.UrlDelimiter + filterAttribute.Value; writer.WriteAttribute(HtmlAttributeId.Src, value); } }
public ActionResult FileUpload(FormCollection formCollection) { using (BTCEntities db = new BTCEntities()) { if (Request.Files != null && Request.Files.Count > 0) { string fileName = string.Empty; string destinationPath = string.Empty; List <Attachments> uploadFileModel = new List <Attachments>(); fileName = Path.GetFileName(Request.Files[0].FileName); if (formCollection.AllKeys.Contains("RFQname") && !string.IsNullOrEmpty(formCollection["RFQname"].ToString()) && formCollection.AllKeys.Contains("RFQSections") && !string.IsNullOrEmpty(formCollection["RFQSections"].ToString())) { destinationPath = Path.Combine(Server.MapPath("~/UploadedFiles/" + MasterRFQ.RFQName + "Pro" + MasterRFQ.ProcessingSection + "Trav" + MasterRFQ.TravelAgencyID) + "/", fileName); Directory.CreateDirectory(Server.MapPath("~/UploadedFiles/" + MasterRFQ.RFQName + "Pro" + MasterRFQ.ProcessingSection + "Trav" + MasterRFQ.TravelAgencyID)); Request.Files[0].SaveAs(destinationPath); var isFileNameRepete = (db.Attachments.AsEnumerable().Where(x => x.FileName == destinationPath).ToList()); if (isFileNameRepete == null || isFileNameRepete.Count <= 0) { Attachments attachments = new Attachments { FileName = fileName, FileType = Request.Files[0].ContentType, FilePath = destinationPath, UploadedDate = DateTime.Now, UploadedBy = dbuser.ID }; db.Attachments.Add(attachments); db.SaveChanges(); AttachmentLink attachmentLink = new AttachmentLink { AttachmentFor = formCollection["RFQname"].ToString() + "Pro" + formCollection["RFQSections"].ToString() + "Trav" + MasterRFQ.TravelAgencyID, AttachmentForID = attachments.ID }; db.AttachmentLink.Add(attachmentLink); db.SaveChanges(); ViewBag.SuccessMessage = "File Uploaded Successfully"; } else { ViewBag.WarningMessage = "File is already exists"; } } } ViewBag.fileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == (MasterRFQ.RFQName + "Pro" + MasterRFQ.ProcessingSection + "Trav" + MasterRFQ.TravelAgencyID)).Select(x => x.Attachments).ToList(); return(RedirectToAction("PreviewRFQ", new { id = MasterRFQ.ID })); } }
public AttachmentWellInfo(AttachmentCollection collection, AttachmentLink attachmentLink, bool isJunkOrPhishing) { this.collection = collection; this.attachmentId = attachmentLink.AttachmentId; if (isJunkOrPhishing) { this.attachmentLevel = AttachmentPolicy.Level.Block; } else { this.attachmentLevel = AttachmentLevelLookup.GetAttachmentLevel(attachmentLink, UserContextManager.GetUserContext()); } this.attachmentType = attachmentLink.AttachmentType; this.fileName = attachmentLink.Filename; this.displayName = attachmentLink.DisplayName; this.isInline = attachmentLink.IsInline(true); this.attachmentSize = attachmentLink.Size; this.fileExtension = attachmentLink.FileExtension; this.attachmentName = AttachmentUtility.CalculateAttachmentName(attachmentLink.DisplayName, attachmentLink.Filename); this.mimeType = attachmentLink.ContentType; }
private void RestoreInlineAttachment(HtmlTagContextAttribute filterAttribute, HtmlTagContext context, HtmlWriter writer) { string text = filterAttribute.Value; string value = filterAttribute.Value; text = HttpUtility.UrlDecode(text); if (!string.IsNullOrEmpty(text)) { int num = value.IndexOf(OwaSafeHtmlCallbackBase.AttachmentBaseUrl, StringComparison.Ordinal); if (num != -1 && this.Item != null && this.Item.Id != null) { if (AttachmentUtility.VerifyInlineAttachmentUrlValidity(value, this.item)) { int contentIdIndex; string contentId = AttachmentUtility.ParseInlineAttachmentContentId(text, out contentIdIndex); string attachmentIdString = AttachmentUtility.ParseInlineAttachmentIdString(text, contentIdIndex); AttachmentLink attachmentLink = AttachmentUtility.GetAttachmentLink(attachmentIdString, contentId, this.item, this); if (attachmentLink != null) { filterAttribute.WriteName(); writer.WriteAttributeValue(this.inlineHTMLAttachmentScheme + AttachmentUtility.GetOrGenerateAttachContentId(attachmentLink)); return; } } } else { if (text.IndexOf(OwaSafeHtmlCallbackBase.blankImageFileName, StringComparison.Ordinal) != -1) { filterAttribute.WriteName(); writer.WriteAttributeValue(OwaSafeHtmlCallbackBase.DoubleBlank); return; } filterAttribute.Write(); } } }
protected void OutputInlineReference(HtmlTagContextAttribute filterAttribute, HtmlTagContext context, AttachmentLink imageAttachmentLink, HtmlWriter writer) { AttachmentPolicy.Level attachmentLevel = this.GetAttachmentLevel(imageAttachmentLink); if (AttachmentPolicy.Level.Allow == attachmentLevel && filterAttribute.Id == HtmlAttributeId.Href) { writer.WriteAttribute(HtmlAttributeId.Src, this.GetInlineReferenceUrl(attachmentLevel, imageAttachmentLink, writer)); return; } string value; if (this.owaContext.ShouldDeferInlineImages) { value = this.owaContext.UserContext.GetThemeFileUrl(ThemeFileId.Clear1x1) + "#" + OwaSafeHtmlOutboundCallbacks.DeferImageUrlDelimiter + this.GetInlineReferenceUrl(attachmentLevel, imageAttachmentLink, writer); } else { value = this.GetInlineReferenceUrl(attachmentLevel, imageAttachmentLink, writer); } writer.WriteAttribute(filterAttribute.Id, value); }
/// <summary> /// Initializes a new instance of the <see cref="ConfigurationAttachmentLink"/> class. /// </summary> /// <param name="attachmentLink">The attachment link.</param> public ConfigurationAttachmentLink(AttachmentLink attachmentLink) { Mode = attachmentLink.Mode; }
public override void ProcessTag(HtmlTagContext context, HtmlWriter writer) { bool flag = false; bool flag2 = false; bool flag3 = false; bool flag4 = false; string text = null; string text2 = null; string text3 = null; AttachmentLink attachmentLink = null; if (context.TagId == HtmlTagId.Link) { context.DeleteTag(); return; } if (context.TagId == HtmlTagId.Head) { if (this.owaContext.UserContext.IsBasicExperience || this.bodyFormat != BodyFormat.TextPlain) { context.WriteTag(true); return; } if (!context.IsEndTag) { context.WriteTag(true); context.InvokeCallbackForEndTag(); return; } writer.WriteStartTag(HtmlTagId.Style); writer.WriteText("div.PlainText "); if (ObjectClass.IsSmsMessage(this.objectClass)) { writer.WriteText(OwaPlainTextStyle.GetStyleFromUserOption(this.owaContext.UserContext.UserOptions)); } else { writer.WriteText(OwaPlainTextStyle.GetStyleFromCharset(this.charSet)); } writer.WriteEndTag(HtmlTagId.Style); context.WriteTag(true); return; } else { if (this.isOutputFragment && context.TagId == HtmlTagId.Form) { context.DeleteTag(); return; } if (context.TagId == HtmlTagId.Form || (!this.isOutputFragment && OwaSafeHtmlOutboundCallbacks.IsFormElementTag(context.TagId))) { this.ProcessUnfragFormTagContext(context, writer); return; } if (context.TagId == HtmlTagId.Base) { foreach (HtmlTagContextAttribute attribute in context.Attributes) { if (OwaSafeHtmlCallbackBase.IsBaseTag(context.TagId, attribute)) { string value = attribute.Value; this.baseRef = Utilities.TryParseUri(value); break; } } return; } foreach (HtmlTagContextAttribute filterAttribute in context.Attributes) { if (filterAttribute.Id == HtmlAttributeId.Src || filterAttribute.Id == HtmlAttributeId.Href) { if (context.TagId == HtmlTagId.Img && string.IsNullOrEmpty(filterAttribute.Value)) { return; } if (string.CompareOrdinal(filterAttribute.Value, this.inlineRTFattachmentScheme) == 0 || filterAttribute.Value.StartsWith(this.inlineHTMLAttachmentScheme, StringComparison.OrdinalIgnoreCase)) { attachmentLink = this.IsInlineImage(filterAttribute); if (attachmentLink == null) { return; } if (context.TagId != HtmlTagId.Img) { writer.WriteEmptyElementTag(HtmlTagId.Img); this.OutputInlineReference(filterAttribute, context, attachmentLink, writer); context.DeleteTag(false); context.DeleteInnerContent(); return; } flag2 = true; break; } else { if (string.CompareOrdinal(filterAttribute.Value, this.embeddedRTFImage) == 0) { this.hasRtfEmbeddedImages = true; break; } break; } } } context.WriteTag(); foreach (HtmlTagContextAttribute htmlTagContextAttribute in context.Attributes) { if (!this.isOutputFragment || htmlTagContextAttribute.Id != HtmlAttributeId.Name || !OwaSafeHtmlOutboundCallbacks.IsFormElementTag(context.TagId)) { if (htmlTagContextAttribute.Id == HtmlAttributeId.UseMap) { this.ProcessUseMapAttribute(htmlTagContextAttribute, context, writer); } else if (OwaSafeHtmlCallbackBase.IsUrlTag(context.TagId, htmlTagContextAttribute)) { if (!flag) { this.ProcessHtmlUrlTag(htmlTagContextAttribute, context, writer); flag = true; } } else if (OwaSafeHtmlCallbackBase.IsImageTag(context.TagId, htmlTagContextAttribute)) { if (htmlTagContextAttribute.Id == HtmlAttributeId.Src && attachmentLink != null) { this.OutputInlineReference(htmlTagContextAttribute, context, attachmentLink, writer); } else { if ((htmlTagContextAttribute.Id != HtmlAttributeId.Src || flag2) && (htmlTagContextAttribute.Id != HtmlAttributeId.DynSrc || flag3) && (htmlTagContextAttribute.Id != HtmlAttributeId.LowSrc || flag4)) { continue; } this.ProcessImageTag(htmlTagContextAttribute, context, writer); } if (htmlTagContextAttribute.Id == HtmlAttributeId.Src) { flag2 = true; } else if (htmlTagContextAttribute.Id == HtmlAttributeId.DynSrc) { flag3 = true; } else if (htmlTagContextAttribute.Id == HtmlAttributeId.LowSrc) { flag4 = true; } } else if (OwaSafeHtmlCallbackBase.IsBackgroundAttribute(htmlTagContextAttribute)) { if (this.isOutputFragment && context.TagId == HtmlTagId.Div) { attachmentLink = this.IsInlineImage(htmlTagContextAttribute); if (attachmentLink != null) { AttachmentPolicy.Level attachmentLevel = this.GetAttachmentLevel(attachmentLink); if (AttachmentPolicy.Level.Allow == attachmentLevel) { writer.WriteAttribute(HtmlAttributeId.Style, "background:url('" + this.GetInlineReferenceUrl(attachmentLevel, attachmentLink, writer) + "');"); } } } else { this.ProcessImageTag(htmlTagContextAttribute, context, writer); } } else if (!OwaSafeHtmlOutboundCallbacks.IsTargetTagInAnchor(context.TagId, htmlTagContextAttribute)) { if (OwaSafeHtmlCallbackBase.IsSanitizingAttribute(htmlTagContextAttribute)) { if (htmlTagContextAttribute.Id == HtmlAttributeId.Border) { text = htmlTagContextAttribute.Value; } else if (htmlTagContextAttribute.Id == HtmlAttributeId.Height) { text2 = htmlTagContextAttribute.Value; } else if (htmlTagContextAttribute.Id == HtmlAttributeId.Width) { text3 = htmlTagContextAttribute.Value; } } else { htmlTagContextAttribute.Write(); } } } } if (!string.IsNullOrEmpty(text2) && !string.IsNullOrEmpty(text3) && this.hasBlockedImagesInCurrentPass) { OwaSafeHtmlOutboundCallbacks.SanitizeImage(writer, text, text2, text3); } else if (!this.hasBlockedImagesInCurrentPass) { if (!string.IsNullOrEmpty(text2)) { writer.WriteAttribute(HtmlAttributeId.Height, text2); } if (!string.IsNullOrEmpty(text3)) { writer.WriteAttribute(HtmlAttributeId.Width, text3); } if (!string.IsNullOrEmpty(text)) { writer.WriteAttribute(HtmlAttributeId.Border, text); } } if (this.hasFoundNonLocalUrlInCurrentPass) { if (this.owaContext.UserContext.IsBasicExperience) { if (!this.hasFoundMailToUrlInCurrentPass || this.openMailtoInNewWindow) { this.WriteSafeTargetBlank(writer); } } else { this.WriteSafeTargetBlank(writer); } } this.hasBlockedImagesInCurrentPass = false; this.hasFoundNonLocalUrlInCurrentPass = false; this.hasFoundMailToUrlInCurrentPass = false; return; } }
/// <summary> /// Uploads a file and links it to an entity /// </summary> /// <param name="InputData">Either a string or a byte[] to upload</param> /// <param name="DocumentName">Name of the document entity in Clarizen</param> /// <param name="FileType">File Type in Clarizen, e.g. /FileType/PDF</param> /// <param name="DocumentType">Document Type in Clarizen, e.g. /DocumentType/YourCustomType (Optional)</param> /// <param name="LinkedEntity">An entity in Clarizen to link the uploaded file to (Optional)</param> /// <returns></returns> public async Task <bool> Upload(object InputData, string DocumentName, string FileName, EntityId FileType, EntityId DocumentType = null, EntityId LinkedEntity = null) { Logs = new Ekin.Log.LogFactory(); #region Validate input if (InputData == null) { Logs.AddError("Ekin.Clarizen.FileUploadHelper", "Upload", "InputData cannot be null"); return(false); } if (!(InputData is string || InputData is byte[])) { Logs.AddError("Ekin.Clarizen.FileUploadHelper", "Upload", "InputData should be a string or a byte array"); return(false); } #endregion Validate input #region Create a Document entity Document document = new Document { Id = "/Document", Name = DocumentName, FileType = FileType, DocumentType = DocumentType }; Ekin.Clarizen.Data.Objects_put clarizenDocument = await ClarizenAPI.CreateObject(document.Id, document); if (!clarizenDocument.IsCalledSuccessfully || clarizenDocument.Data == null || string.IsNullOrWhiteSpace(clarizenDocument.Data.Id)) { Logs.AddError("Ekin.Clarizen.FileUploadHelper", "Upload", "Blank document couldn't be created in Clarizen. Error: " + clarizenDocument.Error); return(false); } else { document.Id = clarizenDocument.Data.Id; } #endregion Create a Document entity #region Get Upload URL from Clarizen Ekin.Clarizen.Files.GetUploadUrl uploadUrlCall = await ClarizenAPI.GetUploadUrl(); if (!uploadUrlCall.IsCalledSuccessfully || uploadUrlCall.Data == null || string.IsNullOrWhiteSpace(uploadUrlCall.Data.UploadUrl)) { Logs.AddError("Ekin.Clarizen.FileUploadHelper", "Upload", "Document upload url couldn't be retrieved from Clarizen. Error: " + uploadUrlCall.Error); return(false); } string uploadUrl = uploadUrlCall.Data.UploadUrl; #endregion Get Upload URL from Clarizen #region Send the file to the Upload URL using (var client = new HttpClient()) { using (var formData = new MultipartFormDataContent()) { if (InputData is string) { formData.Add(new StringContent((string)InputData), "file", FileName); } else if (InputData is byte[]) { formData.Add(new ByteArrayContent((byte[])InputData), "file", FileName); } HttpResponseMessage response = await client.PostAsync(uploadUrl, formData).ConfigureAwait(false); if (!response.IsSuccessStatusCode) { using (HttpContent content = response.Content) { string data = await content.ReadAsStringAsync().ConfigureAwait(false); Logs.AddError("Ekin.Clarizen.FileUploadHelper", "Upload", "Document couldn't be uploaded. Error: " + data); } return(false); } System.IO.Stream resultStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); } } #endregion Send the file to the Upload URL #region Complete the Upload var subType = ""; var extendedInfo = ""; var fileInformation = new FileInformation(StorageType.Server, document.Id, FileName, subType, extendedInfo); var uploadRequest = new Ekin.Clarizen.Files.Request.Upload(document.Id, fileInformation, uploadUrl); CallSettings callSettings = CallSettings.GetFromAPI(ClarizenAPI); callSettings.IsBulk = false; var uploadCall = new Ekin.Clarizen.Files.Upload(uploadRequest, callSettings); bool uploadResult = await uploadCall.Execute(); if (!uploadResult) { Logs.AddError("Ekin.Clarizen.FileUploadHelper", "Upload", "Document couldn't be uploaded to Clarizen. Error: " + uploadCall.Error); return(false); } #endregion Complete the Upload #region If a LinkedEntity object is provided link the file to it if (LinkedEntity != null) { AttachmentLink attachmentLink = new AttachmentLink { Id = "/AttachmentLink", Entity = LinkedEntity, Document = new EntityId(document.Id) }; Ekin.Clarizen.Data.Objects_put clarizenDocumentLink = await ClarizenAPI.CreateObject(attachmentLink.Id, attachmentLink); if (!clarizenDocumentLink.IsCalledSuccessfully || clarizenDocumentLink.Data == null || clarizenDocumentLink.Data.Id == null) { Logs.AddError("Ekin.Clarizen.FileUploadHelper", "Upload", "Document successfully created in Clarizen but it could not be linked to the System Admin user. Error: " + clarizenDocumentLink.Error); return(false); } } #endregion If a LinkedEntity object is provided link the file to it return(true); }
protected void OutputInlineReference(HtmlTagContextAttribute filterAttribute, AttachmentLink link, HtmlWriter writer) { AttachmentPolicy.Level attachmentLevel = this.GetAttachmentLevel(link); if (AttachmentPolicy.Level.Allow != attachmentLevel) { this.hasBlockedImagesInCurrentPass = true; this.hasBlockedInlineAttachments = true; writer.WriteAttribute(filterAttribute.Id, " "); return; } if (!this.isembeddedItem) { StringBuilder stringBuilder = new StringBuilder("/Microsoft-Server-ActiveSync?Cmd=GetAttachment&AttachmentName="); int num = 0; foreach (AttachmentLink attachmentLink in base.AttachmentLinks) { if (link.AttachmentId == attachmentLink.AttachmentId) { break; } num++; } stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}:{1}", new object[] { this.itemId.ToBase64String(), num }); writer.WriteAttribute(filterAttribute.Id, stringBuilder.ToString()); return; } filterAttribute.WriteName(); writer.WriteAttributeValue("cid:" + this.GetOrGenerateAttachContentId(link)); }