Exemple #1
0
        protected void addBtn_Click(object sender, EventArgs e)
        {
            News newsObj = new News();

            newsObj.newsAgencyId = Convert.ToInt32(Agencies.SelectedValue);
            newsObj.category     = CategoryBox.Text;
            newsObj.title        = tileBox.Text;
            newsObj.newsAbstract = AbstractBox.Text;
            newsObj.text         = NewsText.Text;
            newsObj.date         = DateTime.Now;
            newsObj.totalReads   = 0;
            byte[] imgarray = null;
            if (!photo.HasFile)
            {
                string url = "images/noimg.jpg";
                imgarray = System.IO.File.ReadAllBytes(HttpContext.Current.Server.MapPath(url));
            }
            else
            {
                int imagefilelenth = photo.PostedFile.ContentLength;
                imgarray = new byte[imagefilelenth];
                BinaryReader br = new BinaryReader(photo.PostedFile.InputStream);
                imgarray = br.ReadBytes(photo.PostedFile.ContentLength);
            }
            newsObj.photo = imgarray;
            try
            {
                mgr.addNews(newsObj);
                msgLbl.Text            = "New is added sucssessfully";
                tileBox.Text           = "";
                AbstractBox.Text       = "";
                NewsText.Text          = "";
                Agencies.SelectedIndex = 0;
                Agencies.SelectedValue = "";
                photo.Dispose();
            }
            catch
            {
                msgLbl.Text = "There is an error..";
            }
        }