Esempio n. 1
0
        protected void GetDocButtonClick(object sender, EventArgs e)
        {
            Button button = (Button)sender;
            {
                var userIdtmp = Session["UserID"];
                if (userIdtmp == null)
                {
                    Response.Redirect("~/Default.aspx");
                }
                int userId = (int)userIdtmp;
                var appid  = button.CommandArgument;
                int idapp  = Convert.ToInt32(appid);
                CompetitionDataContext competitionDataBase = new CompetitionDataContext();
                zCompetitionsTable     currentCompetition  = (from a in competitionDataBase.zCompetitionsTable
                                                              join b in competitionDataBase.zApplicationTable
                                                              on a.ID equals b.FK_CompetitionTable
                                                              where b.ID == idapp
                                                              select a).FirstOrDefault();

                string dirPath          = Server.MapPath("~/documents/byApplication/" + idapp);
                string templateFilePath = Server.MapPath("~/documents/templates") + "\\" + currentCompetition.ID.ToString() + "\\" + currentCompetition.TemplateDocName;
                string newFileName      = "Заявка " + currentCompetition.TemplateDocName + ".doc";
                newFileName = newFileName.Replace(":", "_");
                string        newFilePath   = dirPath + "\\" + newFileName;
                string        zipFile       = Server.MapPath("~/documents/generatedZipFiles/") + idapp + ".zip";
                string        extractPath   = Server.MapPath("~/documents/extract/");
                CreateXmlFile createXmlFile = new CreateXmlFile();
                string        asdadasdda    = System.Web.HttpContext.Current.Server.MapPath("~/") + @"documents\generatedZipFiles\" + idapp + ".zip";
                createXmlFile.CreateDocument(templateFilePath, newFilePath, idapp, 0);

                if (File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/") + @"documents\generatedZipFiles\" + idapp + ".zip"))
                {
                    File.Delete(System.Web.HttpContext.Current.Server.MapPath("~/") + @"documents\generatedZipFiles\" + idapp + ".zip");
                    ZipFile.CreateFromDirectory(dirPath, zipFile);
                    HttpContext.Current.Response.ContentType = "application/x-zip-compressed";
                    HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=file.zip");
                    HttpContext.Current.Response.BinaryWrite(ReadByteArryFromFile(zipFile));
                    HttpContext.Current.Response.End();
                }
                else
                {
                    ZipFile.CreateFromDirectory(dirPath, zipFile);
                    HttpContext.Current.Response.ContentType = "application/x-zip-compressed";
                    HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=file.zip");
                    HttpContext.Current.Response.BinaryWrite(ReadByteArryFromFile(zipFile));
                    HttpContext.Current.Response.End();
                }
                Response.End();
            }
        }
Esempio n. 2
0
        protected void GetDocButtonClick(object sender, EventArgs e)
        {
            Button button = (Button)sender;
            {
                int iD = Convert.ToInt32(button.CommandArgument);
                CompetitionDataContext competitionDataBase = new CompetitionDataContext();

                zCompetitionsTable currentCompetition = (from a in competitionDataBase.zCompetitionsTable
                                                         join b in competitionDataBase.zApplicationTable
                                                         on a.ID equals b.FK_CompetitionTable
                                                         where b.ID == iD
                                                         select a).FirstOrDefault();
                if (currentCompetition != null)
                {
                    var userIdtmp = Session["UserID"];
                    if (userIdtmp == null)
                    {
                        Response.Redirect("~/Default.aspx");
                    }
                    int userId = (int)userIdtmp;

                    if (currentCompetition.TemplateDocName != null)
                    {
                        if (currentCompetition.TemplateDocName.Any())
                        {
                            string templateFilePath = Server.MapPath("~/documents/templates") + "\\" + currentCompetition.ID.ToString() + "\\" + currentCompetition.TemplateDocName;
                            string newFileName      = "Заявка пользователя на конкурс " + currentCompetition.TemplateDocName;
                            newFileName = newFileName.Replace(":", "_");
                            string newFileDirectory = Server.MapPath("~/documents/generated") + "\\" + iD.ToString();
                            string newFilePath      = newFileDirectory + "\\" + newFileName;


                            Directory.CreateDirectory(newFileDirectory);
                            CreateXmlFile createXmlFile = new CreateXmlFile();
                            int           docType       = 0;

                            try
                            {
                                RadioButtonList newRadioButtonList =
                                    button.Parent.FindControl("RadioButtonList1") as RadioButtonList;
                                docType = Convert.ToInt32(newRadioButtonList.SelectedValue);
                            }
                            catch (Exception)
                            {
                                throw;
                            }
                            createXmlFile.CreateDocument(templateFilePath, newFilePath, iD, docType);
                            string convertedFilePath = createXmlFile.ConvertedFilePath;



                            HttpContext.Current.Response.ContentType = "application/x-zip-compressed";
                            HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=document." + createXmlFile.ConvertedFileExtension);
                            HttpContext.Current.Response.BinaryWrite(ReadByteArryFromFile(convertedFilePath));
                            HttpContext.Current.Response.End();
                            Response.End();

                            /*  System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
                             * response.ClearContent();
                             * response.Clear();
                             * response.ContentType = "text/plain";
                             * response.AddHeader("Content-Disposition", "attachment; filename=document." + createXmlFile.ConvertedFileExtension);
                             * response.TransmitFile(convertedFilePath);
                             * response.Flush();
                             * response.Clear();
                             * response.Redirect("~/User/UserMainPage.aspx");
                             * response.End();
                             *
                             */
                            /*
                             * Response.WriteFile(convertedFilePath);
                             * Response.Redirect("~/User/UserMainPage.aspx");*/
                        }
                    }
                }
            }
            //Response.Redirect("UserMainPage.aspx");
        }