public static string getDocInPortoAnexo(string SourceLocation, string NUD) { byte[] result = null; string sUrl = string.Empty; try { ServicoDocumentos sd = new ServicoDocumentos(); sd.Credentials = new NetworkCredential(CMPUsername, CMPPassword); Debug.WriteLine("Obter imagem do documento..."); Debug.WriteLine("NUD: " + NUD); Debug.WriteLine("Nome do ficheiro: " + SourceLocation); var a = sd.ConsultarAnexoDocumento(NUD, SourceLocation); result = a.FICHEIRO; Debug.WriteLine("Imagem obtida!"); Debug.WriteLine("A gerar ficheiro..."); string gisaTempPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\ParadigmaXis\\GISA"; string fileName = Guid.NewGuid().ToString() + "_" + SourceLocation; FileStream createPdf = new FileStream(gisaTempPath + "\\" + fileName, FileMode.Create); createPdf.Write(result, 0, result.Length); createPdf.Close(); Debug.WriteLine("Ficheiro gerado!"); sUrl = gisaTempPath + "\\" + fileName; } catch (System.Web.Services.Protocols.SoapException ex) { MessageBox.Show("Ocorreu um erro ao obter o ficheiro." + System.Environment.NewLine + System.Environment.NewLine + ex.Message, "Obter ficheiro", MessageBoxButtons.OK, MessageBoxIcon.Error); Trace.WriteLine(ex.Message + System.Environment.NewLine + ex.StackTrace); } catch (Exception e) { MessageBox.Show("Servidor inacessível.", "Servidor", MessageBoxButtons.OK, MessageBoxIcon.Error); Trace.WriteLine(e.ToString()); } return sUrl; }
public static string[] RetrieveAnexosAndWriteToFiles(string username, string password, string timestamp, long limit) { List<string> filenames = new List<string>(); ServicoDocumentos sd = new ServicoDocumentos(); sd.Credentials = new NetworkCredential(username, password); DocumentoInfoArquivoGeral[] diags = sd.ListaDocumentosArquivoGeral(timestamp, limit); foreach (var d in diags) { foreach (var a in d.ARRAYCONTEUDOS.Where(a => a != null)) { ConteudoInfo conteudo = sd.ConsultarAnexoDocumento(d.NUD, a.NOMEFICHEIRO); filenames.Add(conteudo.NOMEFICHEIRO); var stream = new System.IO.FileStream(conteudo.NOMEFICHEIRO, System.IO.FileMode.CreateNew); stream.Write(conteudo.FICHEIRO, 0, conteudo.FICHEIRO.Length); stream.Close(); } } return filenames.ToArray(); }