예제 #1
0
 public void DeleteFiles(int FileID, string FileName, int CourseItemID, int SystemObjectID, int CourseID)
 {
     FilesDAL objFilesDAL = new FilesDAL();
     string ItemType = null;
     if (SystemObjectID == Convert.ToInt32(SystemObject.Discussion))
     {
         ItemType = "~/Images/" + SystemObject.Discussion + "/" + CourseItemID + "/";
     }
     if (SystemObjectID == Convert.ToInt32(SystemObject.Questions))
     {
         ItemType = "~/Images/" + SystemObject.Questions + "/" + CourseItemID + "/";
     }
     if (SystemObjectID == Convert.ToInt32(SystemObject.Terms))
     {
         ItemType = "~/Images/" + SystemObject.Terms + "/" + CourseItemID + "/";
     }
     if (SystemObjectID == Convert.ToInt32(SystemObject.Summary))
     {
         ItemType = "~/Images/" + SystemObject.Summary + "/" + CourseItemID + "/";
     }
     if (SystemObjectID == Convert.ToInt32(SystemObject.Notes))
     {
         ItemType = "~/Images/" + SystemObject.Notes + "/" + CourseItemID + "/";
     }
     string FileToMove = ItemType;
     bool folderExist = System.IO.Directory.Exists(Server.MapPath(FileToMove));
     if (folderExist)
     {
         System.IO.FileInfo F = new System.IO.FileInfo(Server.MapPath(FileToMove + FileName));
         if (F.Exists)
         {
             F.IsReadOnly = false;
             F.Delete();
             objFilesDAL.DeleteFiles(FileID);
         }
     }
 }
예제 #2
0
 public ActionResult FileDisplay(int CourseItemID, int CourseID, int SystemObjectID)
 {
     FilesDAL objFilesDAL = new FilesDAL();
     return View(objFilesDAL.GetFiles(CourseItemID,CourseID,SystemObjectID));
 }
예제 #3
0
        public void SaveAddItem(int CourseItemID, int CourseID, string CourseItemTitle, string ItemDesc, int Chapter, int Section, int PageNumber, string systemobjectName, int AccountID)
        {
            // Save CourseItem
            string Search = "$%comma";
            string replace = "'";
            if (!string.IsNullOrEmpty(ItemDesc))
            {
                ItemDesc = ItemDesc.Replace(Search, replace);
            }
            CourseItem objCourseItem = new CourseItem();
            int? parentid = null;
            int? result = null;
            int SystemObjectID = (int)Enum.Parse(typeof(SystemObject), systemobjectName);
            result =  objCourseItem.SaveCourseItem(CourseItemID, CourseID, AccountID, SystemObjectID, systemobjectName, ItemDesc, parentid, CourseItemTitle, Chapter, Section, PageNumber);

            string strFile = "~/Images/TempAttachment/" + Convert.ToInt64(AccountID).ToString() + "/";
            string FileToMove = "~/Images/" + systemobjectName + "/" + result + "/";
            bool folderExist = System.IO.Directory.Exists(Server.MapPath(strFile));

            #region Move Files To Corresponding Folder From Temparory Folder

            if (folderExist)
            {
                string[] files = System.IO.Directory.GetFiles(Server.MapPath(strFile));

                // Copy the files and overwrite destination files if they already exist.
                foreach (string s in files)
                {
                    string fileName = "";
                    string destFile = "";
                    // Use static Path methods to extract only the file name from the path.
                    fileName = System.IO.Path.GetFileName(s);

                    bool FileToMoveFolderExist = System.IO.Directory.Exists(Server.MapPath(FileToMove));
                    if (!FileToMoveFolderExist)
                    {
                        System.IO.Directory.CreateDirectory(Server.MapPath(FileToMove));
                        destFile = System.IO.Path.Combine(FileToMove, fileName);
                        System.IO.FileInfo F = new System.IO.FileInfo(Server.MapPath(FileToMove + fileName.ToString()));
                        if (F.Exists)
                        {
                            F.IsReadOnly = false;
                            F.Delete();
                        }
                        System.IO.File.Copy(s, Server.MapPath(destFile), true);
                        System.IO.File.Delete(Server.MapPath(strFile + fileName));
                    }
                    else
                    {
                        destFile = System.IO.Path.Combine(FileToMove, fileName);
                        System.IO.FileInfo F = new System.IO.FileInfo(Server.MapPath(FileToMove + fileName.ToString()));
                        if (F.Exists)
                        {
                            F.IsReadOnly = false;
                            F.Delete();
                        }
                        System.IO.File.Copy(s, Server.MapPath(destFile), true);
                        System.IO.File.Delete(Server.MapPath(strFile + fileName));
                    }

                    #region Save Files Detail Into Database
                    // Save File detail into Data Base
                    string FileExtensions = null;
                    string DBFileName = null;
                    DBFileName = fileName;
                    char[] ch = { '.' };
                    string[] str1 = fileName.Split(ch);
                    FileExtensions = str1[1].ToString();
                    FilesDAL objFileDAL = new FilesDAL();
                    objFileDAL.SaveFileDetail(Convert.ToInt32(result), CourseID, AccountID, SystemObjectID, FileExtensions, DBFileName);
                    #endregion
                }
                System.IO.Directory.Delete(Server.MapPath(strFile));
            }

            #endregion
        }