vgurunathaprasad

Forum Replies Created

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • in reply to: SdtContentDropDownList, Open XML, C# #3862

    vgurunathaprasad
    Participant

    element.InnerText

    will work

    in reply to: Form feed #3659

    vgurunathaprasad
    Participant

    Hi Manu,
    Can you give a snap shot of the innerXml of the paragraph or sample document, It will be easy to help


    vgurunathaprasad
    Participant

    Finally this is what I did,

    string fileName = @"text1.docx";
                using (var document = WordprocessingDocument.Open(fileName, true)) {
                    var docPart = document.MainDocumentPart;
                    var doc = docPart.Document;
    
                    DocumentFormat.OpenXml.Wordprocessing.Table myTable = doc.Body.Descendants<DocumentFormat.OpenXml.Wordprocessing.Table>().First();
    
                    
    
                    foreach (TableRow row in myTable.Elements<TableRow>()) {
                        foreach (TableCell cell in row.Elements<TableCell>()) {
                            
                            List<Paragraph> paras = cell.Descendants<DocumentFormat.OpenXml.Wordprocessing.Paragraph>().ToList();
                            foreach (Paragraph p in paras) {
                                
                                string d = p.InnerXml;
                                if (d.Contains("w:drawing")) {
                                    Console.WriteLine("Dude this is a image");
                                    
    
                                    string[] st = Regex.Split(d,"r:embed=\"");
                                    st = Regex.Split(st[1],"\"");
                                    
                                    string rid = st[0];
                                    var imageData = (ImagePart)docPart.GetPartById(rid);
                                    var stream = imageData.GetStream();
                                    var byteStream = new byte[stream.Length];
                                    int length = (int)stream.Length;
                                    stream.Read(byteStream, 0, length);
                                    string outputFilename = rid;
                                    // Write bytestream to disk
                                    using (var fileStream = new FileStream(outputFilename, FileMode.OpenOrCreate)) {
                                        fileStream.Write(byteStream, 0, length);
                                    }
                                    string result = "";
                                    try {
                                        WebClient client = new WebClient();
                                        client.Credentials = CredentialCache.DefaultCredentials;
                                        byte[] rep = client.UploadFile(@"http://localhost:8080/UploadFileServlet/upload", "POST", outputFilename);
                                        result = System.Text.Encoding.UTF8.GetString(rep);
                                        Console.WriteLine("------------>"+result);
                                        //string webData = client.DownloadString(@"http://localhost:8080/UploadFileServlet/upload");
                                        //Console.WriteLine("######################"+webData);
                                        client.Dispose();
                                    } catch (Exception err) {
                                        Console.WriteLine(err.Message);
                                    }
                                    Console.WriteLine(d);
                                    p.InnerXml = "";
                                    
                                    Paragraph para = p.InsertBeforeSelf(new Paragraph());
                                    Run run = para.AppendChild(new Run());
                                    run.AppendChild(new Text("<img srv='"+result+"' alt='"+result+"' />"));
    
                                   
                                } else {
                                    Console.Write("--n--");
                                }
                            }                  
                        } Console.WriteLine();
                    } Console.WriteLine();
                    
    
                   
                    doc.Save();
                }

    Thank you so n much …
    and sorry for the late reply


    vgurunathaprasad
    Participant

    Thank You So much sir, I will work on it and echo you back the results ASAP.

Viewing 4 posts - 1 through 4 (of 4 total)