/// <summary> /// Recupera el texto plano de un documento de Publisher /// </summary> /// <returns></returns> //private StringBuilder GetTextFromPublisher(string path) //{ // StringBuilder text = new StringBuilder(); // Publisher.Application pbApp = new Publisher.Application(); // Publisher.Document pbDoc = pbApp.Open(path, true, true, Publisher.PbSaveOptions.pbDoNotSaveChanges); // Publisher.Pages pgs = pbDoc.Pages; // foreach (Publisher.Page pg in pgs) // { // foreach (Publisher.Shape shp in // pg.Shapes) // { // if (shp.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue) // { // //fulltext += shp.TextFrame.TextRange.Text; // text.Append(shp.TextFrame.TextRange.Text).Append(" "); // } // else if (shp.HasTable == Microsoft.Office.Core.MsoTriState.msoTrue) // { // text.Append(" "); // //fulltext += "TABLE!!!!"; // To do! // } // } // } // return text; //} public StringBuilder GetTextFromHtml(string html) { const string tagWhiteSpace = @"(>|$)(\W|\n|\r)+<"; //matches one or more (white space or line breaks) between '>' and '<' const string stripFormatting = @"<[^>]*(>|$)"; //match any character between '<' and '>', even when end tag is missing const string lineBreak = @"<(br|BR)\s{0,1}\/{0,1}>"; //matches: <br>,<br/>,<br />,<BR>,<BR/>,<BR /> var lineBreakRegex = new Regex(lineBreak, RegexOptions.Multiline); var stripFormattingRegex = new Regex(stripFormatting, RegexOptions.Multiline); var tagWhiteSpaceRegex = new Regex(tagWhiteSpace, RegexOptions.Multiline); var text = html; //Decode html specific characters text = System.Net.WebUtility.HtmlDecode(text); Escribe.Write("ACH:"); Escribe.Write(text); //Remove tag whitespace/line breaks text = tagWhiteSpaceRegex.Replace(text, "><"); //Replace <br /> with line breaks text = lineBreakRegex.Replace(text, Environment.NewLine); //Strip formatting text = stripFormattingRegex.Replace(text, string.Empty); StringBuilder result = new StringBuilder(text); return(result); }
public async Task <IHttpActionResult> deleteAdjuntoITF(AdjuntoITF id) { try { log.Info(new MDCSet(this.ControllerContext.RouteData)); var model = id; await dbITF.DeleteAdjuntoITF(model.AdjuntoITFId); try { log.Info(new MDCSet(this.ControllerContext.RouteData)); long num = await dbITF.CountAdjuntoITFByRutaCompleta(model.Adjunto.RutaCompleta); if (num == 1) { File.Delete(model.Adjunto.RutaCompleta); } } catch (Exception e) { log.Error(new MDCSet(this.ControllerContext.RouteData), e); Escribe.Write(e); } return(Ok("Elemento eliminado exitosamente!")); } catch (Exception e) { log.Error(new MDCSet(this.ControllerContext.RouteData), e); return(InternalServerError(e)); } }