public ActionResult UploadFile(FormCollection collection)
        {
            var folderPath = (string)Session["UploadPath"];
            var libraryName = (string)Session["LibraryName"];
            var sortField = collection.Get("hdnsortField");
            var sortDir = collection.Get("hdnsortDir");

            try
            {
                var stringArray = new string[15] { @"\", "/", ":", "*", "?", "\"", "<", ">", "|", "#", "{", "}", "%", "~", "&" };

                int numFiles = Request.Files.Count;
                for (int i = 0; i < numFiles; i++)
                {
                    var uploadedFile = Request.Files[i];

                    var filename = Path.GetFileName(uploadedFile.FileName);

                    if (filename.Split('.')[0].Length > 121)
                        throw new Exception(
                            "Please verify file name length, It must be less then equal to 120 char.");

                    if (Request.Files.Count == 1 && filename == string.Empty)
                        throw new Exception("Please select file to upload!");

                    if (Request.Files.Count == 1 &&
                        (ContainAnyOf(filename, stringArray) || uploadedFile.ContentLength <= 0))
                        throw new Exception(
                            "The file name is invalid or the file is empty.	A file name cannot contain any of the following characters: \\ / : * ? \" < > | # { } % ~ &");

                    var streamData = uploadedFile.InputStream;

                    var documentModel = new DocumentLibraryModel()
                                        {
                                            Name = Path.GetFileName(uploadedFile.FileName),
                                            ContentType = "plain/text",
                                            FolderPath = folderPath
                                        };

                    var document = new DocumentLibrary()
                                   {
                                       Name =
                                           new CultureInfo("en").TextInfo.ToTitleCase(documentModel.Name.ToLower()),
                                       FolderPath = documentModel.FolderPath,
                                       LibraryName = libraryName,
                                       Stream = streamData
                                   };
                    if (!string.IsNullOrEmpty(filename))
                        DocumentLibraryService.UploadDocuments(document);

                }

                ViewBag.LibraryName = libraryName;
                ViewBag.UploadPath = folderPath;
                ViewBag.SortField = sortField;
                ViewBag.SortDir = sortDir;
                return RedirectToAction("DocumentContainer", "Documents", new { LibraryName = libraryName, FolderPath = folderPath, SortField = sortField, SortDir = sortDir, Type = "DocLib" });
            }
            catch (Exception ex) { throw ex; }
        }
        public string UploadMultipleFiles()
        {
            var req = Request.InputStream;
            req.Seek(0, SeekOrigin.Begin);
            var json = new StreamReader(req).ReadToEnd();
            FileUpload input = null;
            bool response = true;

            input = JsonConvert.DeserializeObject<FileUpload>(json);//UploadPath
            var libraryName = string.IsNullOrEmpty(Convert.ToString(Session["LibraryName"])) ? input.LibraryName : Convert.ToString(Session["LibraryName"]);
            var folderPath = string.IsNullOrEmpty(Convert.ToString(Session["UploadPath"])) ? input.FolderPath : Convert.ToString(Session["UploadPath"]);
            var sortField = string.Empty;
            var sortDir = string.Empty;

            byte[] byd = Convert.FromBase64String(input.FileStream);

            var documentModel = new DocumentLibraryModel()
            {
                Name = Path.GetFileName(input.Name),
                ContentType = "plain/text",
                FolderPath = folderPath
            };

            var document = new DocumentLibrary()
            {
                Name =
                    new CultureInfo("en").TextInfo.ToTitleCase(documentModel.Name.ToLower()),
                FolderPath = folderPath,
                LibraryName = libraryName,
                Stream = new MemoryStream(byd)
            };
            if (!string.IsNullOrEmpty(input.Name))
            {
             response =DocumentLibraryService.UploadDocuments(document);
            }

            ViewBag.LibraryName = libraryName;
            ViewBag.UploadPath = folderPath;
            ViewBag.SortField = sortField;
            ViewBag.SortDir = sortDir;
            Session["UploadPath"] = folderPath;
            Session["LibraryName"] = libraryName;
            return input.Name + "|" + folderPath + "|" + libraryName  + "|" + response;
        }
        private List<DocumentLibraryModel> GetDocumentModel(string folderPath, string libraryName, string sortField, string sortDir, string Type)
        {
            try
            {
                var account = new AccountInfo();
                var docModel = new DocumentLibraryModel() { FolderPath = folderPath, LibraryName = libraryName, SortField = sortField, SortDir = sortDir };
                var docLib = new DocumentLibrary() { FolderPath = docModel.FolderPath, LibraryName = docModel.LibraryName, SortField = docModel.SortField, SortDir = docModel.SortDir };
                var logInUser = account.GetFullName();

                var documents = DocumentLibraryService.GetAllDocuments(docLib);
                var output = new List<DocumentLibraryModel>();

                foreach (var model in documents)
                {
                    output.Add(new DocumentLibraryModel()
                    {
                        Name = model.Name,
                        Description = model.Description,
                        ContentType = model.ContentType,
                        FolderPath = model.FolderPath,
                        LibraryName = model.LibraryName,
                        RelativePath = model.RelativePath,
                        CreatedBy = model.CreatedBy,
                        CreatedDate = model.CreatedDate,
                        LastUpdated = model.LastUpdated,
                        ModifieddBy = model.ModifieddBy,
                        Permission = new SPPermissionModel() { CanAdd = model.Permission.CanAdd, CanDelete = model.Permission.CanDelete },
                        IsOldVersion = model.IsOldVersion,
                        ImgSrc = model.ImgSrc,
                        CheckedOutUserName = model.CheckedOutUserName,
                        IsCheckedoutToLocal = model.IsCheckedoutToLocal,
                        IsCheckedIn = CheckInStatus(model.CheckedOutUserName),
                        IsCheckedOut = CheckOutStatus(model.CheckedOutUserName),
                        LogInUserName = logInUser
                    });
                }

                var permission = DocumentLibraryService.GetPermission(docLib);
                ViewBag.canAdd = permission.Permission.CanAdd;

                return output;
            }
            catch (Exception ex) { throw ex; }
        }