private void SubmitFileButton_Click(object sender, EventArgs e) { if (fileController.GetFileById(workingFile.Id) == null) { workingFile.Name = FileNameTextBox.Text; fileController.AddFile(workingFile); fileSaved = true; } parentReference.UpdateData(); this.Close(); }
//Thêm File private void btnAddFile_Click(object sender, EventArgs e) { if (txtNameFolder.Text == "") { return; } else { string filename = ""; OpenFileDialog ChooseFile = new OpenFileDialog(); ChooseFile.Filter = "PDF|*.pdf"; if (ChooseFile.ShowDialog() == DialogResult.OK) { filename = ChooseFile.FileName; } int index = FolderController.getListFolder().FindIndex(x => x.namefolder == txtNameFolder.Text); if (FolderController.getListFolder()[index].listfile != null) //giải thích ??? { if (FolderController.getListFolder()[index].listfile.ToList <ClassFile>().Where( //giải thích ??? x => x.namefile == filename).Count() < 1) { AddFileItem(ChooseFile.FileName); //ngân: khắc phục addfile lỗi ClassFile file = new ClassFile(); file.namefile = filename; file.folder.Add(lstFolder.SelectedItem as ClassFolder); //ngân:bổ sung thêm lấy mấy thông tin để đủ 1 hàng bảng file if (FileController.AddFile(file) == false) { //file đã có trong bảng //định xóa file trong bảng, rồi tạo thêm liên kết với folder mới(k bt ảnh hưởng liên kết cũ k- xóa cmnr) ClassFile f = FileController.getFile(file.namefile); if (FileController.DeleteFile(f) == false) { MessageBox.Show("Remove Task Error"); return; } FileController.AddFile(file); } //FolderController.AddFile(FolderController.getListFolder()[index], file); } else { MessageBox.Show("Đã có File này trong danh sách", "Thông Báo"); } } else//giải thích ??? { //AddFileItem(ChooseFile.FileName); //ClassFile file = new ClassFile(); //file.namefile = filename; //FolderController.AddFile(FolderController.getListFolder()[index], file); } } }
//Hàm thêm file lên database và hiển thị lên listview(lstFileName) public void AddFileItem(ClassFolder folder, string filename) { FileInfo iffile = new FileInfo(filename); ClassFile file = new ClassFile(); file.ID = FileController.getIDfromDB(); file.namefile = iffile.Name; file.path = iffile.DirectoryName; file.size = Math.Ceiling(iffile.Length / 1024f).ToString("0 KB"); if (FileController.getContain(file)) { file = FileController.getFile(file.namefile); } else { FileController.AddFile(file); } folder.listfile.Add(file); FolderController.UpdateFolder(folder); }
protected void Save_OnClick(object sender, EventArgs e) { try { if (FolderList.Items.Count == 0) { return; } DotNetNuke.Entities.Portals.PortalSettings portalSettings = DotNetNuke.Entities.Portals.PortalSettings.Current; string fileContents = htmlText2.Text.Trim(); string newFileName = FileName.Text; if (!(newFileName.EndsWith(".html"))) { newFileName = newFileName + ".html"; } string rootFolder = portalSettings.HomeDirectoryMapPath; string dbFolderPath = FolderList.SelectedValue; string virtualFolder = (string)(string)FileSystemValidation.ToVirtualPath(dbFolderPath); rootFolder = rootFolder + FolderList.SelectedValue; rootFolder = rootFolder.Replace("/", "\\"); string errorMessage = string.Empty; FolderController folderCtrl = new FolderController(); FolderInfo folder = folderCtrl.GetFolder(portalSettings.PortalId, dbFolderPath, false); if ((folder == null)) { ShowSaveTemplateMessage(GetString("msgFolderDoesNotExist.Text")); return; } // Check file name is valid FileSystemValidation dnnValidator = new FileSystemValidation(); errorMessage = dnnValidator.OnCreateFile(virtualFolder + newFileName, fileContents.Length); if (!(string.IsNullOrEmpty(errorMessage))) { ShowSaveTemplateMessage(errorMessage); return; } FileController fileCtrl = new FileController(); DotNetNuke.Services.FileSystem.FileInfo existingFile = fileCtrl.GetFile(newFileName, portalSettings.PortalId, folder.FolderID); // error if file exists if (!Overwrite.Checked && existingFile != null) { ShowSaveTemplateMessage(GetString("msgFileExists.Text")); return; } FileInfo newFile = existingFile; if ((newFile == null)) { newFile = new FileInfo(); } newFile.FileName = newFileName; newFile.ContentType = "text/plain"; newFile.Extension = "html"; newFile.Size = fileContents.Length; newFile.FolderId = folder.FolderID; errorMessage = FileSystemUtils.CreateFileFromString(rootFolder, newFile.FileName, fileContents, newFile.ContentType, string.Empty, false); if (!(string.IsNullOrEmpty(errorMessage))) { ShowSaveTemplateMessage(errorMessage); return; } existingFile = fileCtrl.GetFile(newFileName, portalSettings.PortalId, folder.FolderID); if (newFile.FileId != existingFile.FileId) { newFile.FileId = existingFile.FileId; } if (newFile.FileId != Null.NullInteger) { fileCtrl.UpdateFile(newFile.FileId, newFile.FileName, newFile.Extension, newFile.Size, newFile.Width, newFile.Height, newFile.ContentType, folder.FolderPath, folder.FolderID); } else { fileCtrl.AddFile(portalSettings.PortalId, newFile.FileName, newFile.Extension, newFile.Size, newFile.Width, newFile.Height, newFile.ContentType, folder.FolderPath, folder.FolderID, true); } ShowSaveTemplateMessage(string.Empty); } catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); throw ex; } }
private string ExportModule(int ModuleID, string FileName) { string strMessage = ""; ModuleController objModules = new ModuleController(); ModuleInfo objModule = objModules.GetModule(ModuleID, TabId, false); if (objModule != null) { if (objModule.BusinessControllerClass != "" & objModule.IsPortable) { try { object objObject = Reflection.CreateObject(objModule.BusinessControllerClass, objModule.BusinessControllerClass); //Double-check if (objObject is IPortable) { string Content = Convert.ToString(((IPortable)objObject).ExportModule(ModuleID)); if (Content != "") { // add attributes to XML document Content = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + "<content type=\"" + CleanName(objModule.FriendlyName) + "\" version=\"" + objModule.Version + "\">" + Content + "</content>"; //First check the Portal limits will not be exceeded (this is approximate) PortalController objPortalController = new PortalController(); string strFile = PortalSettings.HomeDirectoryMapPath + FileName; if (objPortalController.HasSpaceAvailable(PortalId, Content.Length)) { // save the file StreamWriter objStream = File.CreateText(strFile); objStream.WriteLine(Content); objStream.Close(); // add file to Files table FileController objFiles = new FileController(); FileInfo finfo = new FileInfo(strFile); FolderController objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder(PortalId, ""); Services.FileSystem.FileInfo objFile = objFiles.GetFile(lblFile.Text, PortalId, objFolder.FolderID); if (objFile == null) { objFiles.AddFile(PortalId, lblFile.Text, "xml", finfo.Length, 0, 0, "application/octet-stream", "", objFolder.FolderID, true); } else { objFiles.UpdateFile(objFile.FileId, objFile.FileName, "xml", finfo.Length, 0, 0, "application/octet-stream", "", objFolder.FolderID); } } else { strMessage += "<br>" + string.Format(Localization.GetString("DiskSpaceExceeded"), strFile); } } else { strMessage = Localization.GetString("NoContent", this.LocalResourceFile); } } else { strMessage = Localization.GetString("ExportNotSupported", this.LocalResourceFile); } } catch { strMessage = Localization.GetString("Error", this.LocalResourceFile); } } else { strMessage = Localization.GetString("ExportNotSupported", this.LocalResourceFile); } } return(strMessage); }
public String AddFile(HttpPostedFileBase file) { return(ActiveController.AddFile(file)); }
/// <summary>process import of multi-instance records.</summary> /// <param name="xml">The xml.</param> /// <param name="prefix">The prefix (image, or link)</param> /// <param name="slide">The slide.</param> private static void ProcessImport(XmlNode xml, string prefix, Slide slide) { var ps = DotNetNuke.Entities.Portals.PortalController.GetCurrentPortalSettings(); var contentTypeXml = xml.SelectSingleNode(prefix + "contenttype"); var contentFileNameXml = xml.SelectSingleNode(prefix + "filename"); var contentFileExtensionXml = xml.SelectSingleNode(prefix + "fileextension"); var contentFolderPathXml = xml.SelectSingleNode(prefix + "folderpath"); var contentBase64Xml = xml.SelectSingleNode(prefix + "filedata"); var contentTabPathXml = xml.SelectSingleNode(prefix + "tabpath"); // this item appears to be an encoded tabpath.... lets continue if (contentTabPathXml != null) { // todo, when upgrading DNN reference, switch this to GetTabByTabPath on the TabController var tabInfo = ps.DesktopTabs.Cast <TabInfo>().SingleOrDefault(desktopTab => desktopTab.TabPath == contentTabPathXml.InnerText); if (tabInfo != null) { switch (prefix) { case "image": slide.ImageLink = "TabID=" + tabInfo.TabID.ToString(CultureInfo.InvariantCulture); break; default: slide.Link = "TabID=" + tabInfo.TabID.ToString(CultureInfo.InvariantCulture); break; } } } // this item appears to be an encoded image... lets continue if (contentTypeXml != null && contentBase64Xml != null && contentFolderPathXml != null && contentFileNameXml != null && contentFileExtensionXml != null) { var folderController = new FolderController(); var fileController = new FileController(); // for now, just put imported images into the root folder... var folder = folderController.GetFolder(ps.PortalId, contentFolderPathXml.InnerText, true); if (folder == null) { folderController.AddFolder(ps.PortalId, contentFolderPathXml.InnerText); folder = folderController.GetFolder(ps.PortalId, contentFolderPathXml.InnerText, true); } var file = fileController.GetFile(contentFileNameXml.InnerText, ps.PortalId, folder.FolderID); if (file == null) { var content = Convert.FromBase64String(contentBase64Xml.InnerText); file = new DotNetNuke.Services.FileSystem.FileInfo { PortalId = ps.PortalId, ContentType = contentTypeXml.InnerText, FileName = contentFileNameXml.InnerText, Extension = contentFileExtensionXml.InnerText, FolderId = folder.FolderID, Size = content.Length, }; // save the file the dnn filesystem File.WriteAllBytes(ps.HomeDirectoryMapPath + file.FileName, content); // add the file to the dnn database file.FileId = fileController.AddFile(file); } // update the files content.... just incase, it never hurts.... right? ////fileController.UpdateFileContent(file.FileId, content); switch (prefix) { case "image": slide.ImageLink = "FileID=" + file.FileId.ToString(CultureInfo.InvariantCulture); break; default: slide.Link = "FileID=" + file.FileId.ToString(CultureInfo.InvariantCulture); break; } } }
File InterfaceFile.AddFile(File toBeAdded) { return(fileController.AddFile(toBeAdded)); }