Пример #1
0
        protected void remove5_Click(object sender, EventArgs e)
        {
            string sourcepath = string.Empty;
            DirectoryInfo dirInfo = null;
            string Path1 = remove5.Attributes["imgpath"].ToString();
            sourcepath = Server.MapPath("~" + Path1);

            FileInfo g = new FileInfo(sourcepath);
            if (g.Exists)
                g.Delete();

            int index = strAllImgPath.IndexOf(Path1);
            int leng = Path1.Length;
            int newlength = 0;
            int newindex = 0;

            if (index + leng == strAllImgPath.Length && index == 0)
            {
                newindex = index;
                newlength = leng;
            }
            else if (index + leng == strAllImgPath.Length && index != 0)
            {
                newindex = index - 1;
                newlength = leng + 1;
            }
            else
            {
                newindex = index;
                newlength = leng + 1;
            }

            AdDetailsBll ad = new AdDetailsBll();
            ad.UpdateAdImagePath(Convert.ToInt32(strImageId), strAllImgPath.Remove(newindex, newlength));
            BindUrl();
        }
Пример #2
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            int intError = 0;
            if (FileUpload1.HasFile)
            {
                string[] strTemp = new string[5];
                strTemp = strAllImgPath.Split(':');
                if (FileUpload1.PostedFile.ContentLength > 1048576)
                {
                    errFile1.Visible = true;
                    errFile1.Text = "Exceeds maximum limit 1 MB";
                    intError++;
                }
                else if (strTemp.Length == 5 && strTemp[4] != null && strTemp[4] != "")
                {
                    errFile1.Visible = true;
                    errFile1.Text = "Maximum 5 images are allowed. ";
                    intError++;
                }
                else
                    errFile1.Visible = false;
            }
            else
            {
                string[] strTemp = new string[5];
                strTemp = strAllImgPath.Split(':');
                if (strTemp.Length == 5 && strTemp[4] != null && strTemp[4] != "")
                {
                    errFile1.Visible = true;
                    errFile1.Text = "Maximum 5 images are allowed. ";
                    intError++;
                }
                else
                {
                    errFile1.Visible = true;
                    errFile1.Text = "Select a image file. ";
                    intError++;
                }
            }
            if (intError == 0)
            {
                string path = string.Empty;
                string finalPath = string.Empty;
                string filePath = string.Empty;
                int userId = Convert.ToInt32(Session["UserId"].ToString());
                string sFilename = "";
                if (FileUpload1.PostedFile != null)
                {
                    HttpPostedFile myFile = FileUpload1.PostedFile;
                    int nFileLen = myFile.ContentLength;
                    if (nFileLen != 0)
                    {
                        DirectoryInfo dirInfo = null;
                        string fileSavePath = "/Data/TS_" + userId + "/Images/";
                        path = Server.MapPath("~" + fileSavePath);
                        if (!Directory.Exists(path))
                        {
                            dirInfo = Directory.CreateDirectory(path);
                        }
                        sFilename = System.IO.Path.GetFileName(myFile.FileName);
                        path = path + "/" + sFilename;
                        FileUpload1.PostedFile.SaveAs(path);

                        finalPath = Path.Combine(fileSavePath, sFilename);
                    }
                    if (strAllImgPath.Trim() == "")
                        strAllImgPath = finalPath;
                    else
                        strAllImgPath = strAllImgPath + ":" + finalPath;
                    AdDetailsBll ad = new AdDetailsBll();
                    ad.UpdateAdImagePath(Convert.ToInt32(strImageId), strAllImgPath);
                    BindUrl();

                }
            }
        }