/// <summary> /// This uploads a file which generates a GUID name, uses original image extension as save type. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks></remarks> protected void cmdUpload_Click(System.Object sender, System.EventArgs e) { lblMessage.Text = string.Empty; try { // if no file is selected exit if (fuFile.PostedFile.FileName == string.Empty) { return; } // Maximum attachment filesize = 5MB if (fuFile.PostedFile.InputStream.Length > (/*objConfig.MaxAttachmentSize*/ 5000 * 1024)) { lblMessage.Text = Localization.GetString("MaxFileSize", this.LocalResourceFile) /*+ objConfig.MaxAttachmentSize.ToString()*/ + "5 MB"; return; } string FileName = System.IO.Path.GetFileName(fuFile.PostedFile.FileName); //Get destination folder as mappath string ParentFolderName = PortalSettings.HomeDirectoryMapPath; //ParentFolderName += BaseFolder; ParentFolderName = ParentFolderName.Replace("/", "\\"); if (ParentFolderName.EndsWith("\\") == false) { ParentFolderName += "\\"; } string strExtension = System.IO.Path.GetExtension(fuFile.PostedFile.FileName).Replace(".", ""); if (_fileFilter != string.Empty /*& Strings.InStr("," + _fileFilter.ToLower(), "," + strExtension.ToLower()) == 0*/) { // trying to upload a file not allowed for current filter lblMessage.Text = string.Format(Localization.GetString("UploadError", this.LocalResourceFile), _fileFilter, strExtension); } if (lblMessage.Text == string.Empty) { //ParentFolderName = "C:\\inetpub\\wwwroot\\DNN6\\Portals\\0\\"; string destFileName = Guid.NewGuid().ToString().Replace("-", "") + "." + strExtension; lblMessage.Text = FileSystemUtils.UploadFile(ParentFolderName, fuFile.PostedFile, false); if (lblMessage.Text != string.Empty) { return; } //Rename the file using the GUID model //FileSystemUtils.MoveFile(ParentFolderName + FileName, ParentFolderName + destFileName, PortalSettings); destFileName = FileName; //Now get the FileID from DNN Filesystem int myFileID = 0; ArrayList fileList = Globals.GetFileList(PortalId, strExtension);//, false, ParentFolderName, false); foreach (FileItem objFile in fileList) { if (objFile.Text == destFileName) { myFileID = Convert.ToInt32(objFile.Value); } } if (myFileID > 0) { //Now save the Attachment info AttachmentInfo objAttach = new AttachmentInfo(); var _with1 = objAttach; _with1.PostID = PostId; _with1.UserID = UserId; _with1.FileID = myFileID; _with1.LocalFileName = FileName; _with1.Inline = false; AttachmentController cntAttachment = new AttachmentController(); cntAttachment.Update(objAttach); BindFileList(); } } } catch (Exception exc) { //ProcessModuleLoadException(this, exc); Response.Write(exc); } }
public void Update() { testContext.CreateAdminTeam(); var page = CreateNestedPage(); PageController pc = new PageController(); var children = pc.GetChildren(page.Id, testContext.adminUsers[0]); var subPage = children.Item1[0]; var children2 = pc.GetChildren(subPage.Id, testContext.adminUsers[0]); var att = children2.Item2[0]; // Admin Team Owner var updates = new Dictionary <string, string>(); updates.Add("name", "better"); controller.Update(att.Id, updates, testContext.adminUsers[0]); var fetchedPage = controller.Get(att.Id, testContext.adminUsers[0]); Assert.Equal("better", fetchedPage.Name); // Admin Team Writer updates = new Dictionary <string, string>(); updates.Add("name", "even writer"); controller.Update(att.Id, updates, testContext.adminUsers[1]); fetchedPage = controller.Get(att.Id, testContext.adminUsers[1]); Assert.Equal("even writer", fetchedPage.Name); // Admin Team Nested reader team writer updates = new Dictionary <string, string>(); updates.Add("name", "even reader"); controller.Update(att.Id, updates, testContext.adminUsers[2]); fetchedPage = controller.Get(att.Id, testContext.adminUsers[2]); Assert.Equal("even reader", fetchedPage.Name); // Admin Team Writer updates = new Dictionary <string, string>(); updates.Add("name", "even writer"); controller.Update(att.Id, updates, testContext.adminUsers[3]); fetchedPage = controller.Get(att.Id, testContext.adminUsers[3]); Assert.Equal("even writer", fetchedPage.Name); // Admin Team Nested reader team writer updates = new Dictionary <string, string>(); updates.Add("name", "even reader"); controller.Update(att.Id, updates, testContext.adminUsers[4]); fetchedPage = controller.Get(att.Id, testContext.adminUsers[4]); Assert.Equal("even reader", fetchedPage.Name); // Team Owner reader team writer updates = new Dictionary <string, string>(); updates.Add("name", "even owner"); controller.Update(att.Id, updates, testContext.users[0]); fetchedPage = controller.Get(att.Id, testContext.users[0]); Assert.Equal("even owner", fetchedPage.Name); // Team Writer updates = new Dictionary <string, string>(); updates.Add("name", "even writer"); controller.Update(att.Id, updates, testContext.users[10]); fetchedPage = controller.Get(att.Id, testContext.users[10]); Assert.Equal("even writer", fetchedPage.Name); // Team Reader updates = new Dictionary <string, string>(); updates.Add("name", "even reader "); Assert.Throws <NotAuthorized>(() => controller.Update(att.Id, updates, testContext.users[11])); fetchedPage = controller.Get(att.Id, testContext.users[11]); Assert.Equal("even writer", fetchedPage.Name); // Nested Team Writer writer updates = new Dictionary <string, string>(); updates.Add("name", "even nested writer"); controller.Update(att.Id, updates, testContext.users[3]); fetchedPage = controller.Get(att.Id, testContext.users[3]); Assert.Equal("even nested writer", fetchedPage.Name); // Nested Team Writer reader updates = new Dictionary <string, string>(); updates.Add("name", "even nested reader"); controller.Update(att.Id, updates, testContext.users[4]); fetchedPage = controller.Get(att.Id, testContext.users[4]); Assert.Equal("even nested reader", fetchedPage.Name); // Nested Team Reader writer updates = new Dictionary <string, string>(); updates.Add("name", "even nested reader writer"); Assert.Throws <NotAuthorized>(() => controller.Update(att.Id, updates, testContext.users[5])); fetchedPage = controller.Get(att.Id, testContext.users[5]); Assert.Equal("even nested reader", fetchedPage.Name); // Nested Team reader reader updates = new Dictionary <string, string>(); updates.Add("name", "even nested reader reader"); Assert.Throws <NotAuthorized>(() => controller.Update(att.Id, updates, testContext.users[6])); fetchedPage = controller.Get(att.Id, testContext.users[6]); Assert.Equal("even nested reader", fetchedPage.Name); updates = new Dictionary <string, string>(); updates.Add("name", "no permissions"); Assert.Throws <NotAuthorized>(() => controller.Update(att.Id, updates, testContext.users[7])); Assert.Throws <NotAuthorized>(() => fetchedPage = controller.Get(att.Id, testContext.users[7])); Assert.Equal("even nested reader", fetchedPage.Name); // Check the owner updates = new Dictionary <string, string>(); updates.Add("name", "owner for the win"); controller.Update(att.Id, updates, testContext.users[25]); fetchedPage = controller.Get(att.Id, testContext.users[25]); Assert.Equal("owner for the win", fetchedPage.Name); }