/// <summary> /// Método usado para salvar o arquivo no disco e quando necessário fazer um merge no arquivo. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.ImageClickEventArgs"/> instance containing the event data.</param> protected void ImageButtonSalvar_Click(object sender, ImageClickEventArgs e) { if (FileUpload1.HasFile) { string id = ""; string nameFile = "", abaAtiva; abaAtiva = retornaAbaAtiva(); try { id = obterMatricula(); } catch (Exception ex) { LabelErro.Text = ex.Message; ImageAttention.Visible = true; } //verificar se nao é uma titulaçao if (!abaAtiva.Equals("titulacoes")) { nomeArquivo = montarFormatoGD(id, abaAtiva + ext); } else { if (id.Length == 0) { ScriptManager.RegisterStartupScript(Page, GetType(), Guid.NewGuid().ToString(), "window.alert('Digite a matrícula!');", true); } else { nomeArquivo = adpt.montaFormatoTitulacao(FileUpload1.FileName.ToString(), id, DropDownListTipoProcesso.SelectedValue.ToString()); } } if (id.Length == 0) { ScriptManager.RegisterStartupScript(Page, GetType(), Guid.NewGuid().ToString(), "window.alert('Digite a matrícula!');", true); } else { if (Session["postou_" + abaAtiva].ToString().Equals((string)"sim") && !(abaAtiva.Equals("titulacoes"))) { // Create a merge document and set it's properties MergeDocument document = MergeDocument.Merge(pathDir + nomeArquivo, FileUpload1.PostedFile.FileName); // Outputs the merged document document.Draw(nomeArquivo); System.IO.File.Delete(pathDir + nomeArquivo); System.IO.File.Move(nomeArquivo, pathDir + nomeArquivo); } //se ainda nao postou o documento nao precisa fazer um merge. Ou é uma titulaçao que nao precisa de merge else { try { FileUpload1.SaveAs(pathDir + nomeArquivo); Session.Add("fileName", nomeArquivo); } catch (Exception ex) { LabelErro.Text = ex.Message; ImageAttention.Visible = true; } } TableArquivo.Visible = true; GridView1.Visible = true; LabelArquivo.Text = nomeArquivo; //ImageButtonVer.Visible = true; ImageButtonDelete.Visible = true; //levantar flag dizendo que o arquivo foi postado Session.Add("postou_" + abaAtiva, "sim"); Arquivo arq = new Arquivo(); arq.nome_Arquivo = nomeArquivo; arq.tipo_Arquivo = abaAtiva; List <Arquivo> lista = new List <Arquivo>(); lista = (List <Arquivo>)Session["arquivos"]; if (lista == null) { lista = new List <Arquivo>(); } lista.Add(arq); Session["arquivos"] = lista; carrega_Grid("arquivos"); } } else { //Mostra o Erro quando não tem arquivo selecionado LabelErro.Text = "Selecione o arquivo"; ImageAttention.Visible = true; } }