示例#1
0
        protected void cmdSave_Click(object sender, EventArgs e)
        {
            // if no file is selected exit
            if (txtFile.PostedFile.FileName == "")
            {
                return;
            }

            string ParentFolderName;

            if (PortalSettings.ActiveTab.ParentId == PortalSettings.SuperTabId)
            {
                ParentFolderName = Globals.HostMapPath;
            }
            else
            {
                ParentFolderName = PortalSettings.HomeDirectoryMapPath;
            }
            ParentFolderName += cboFolders.SelectedItem.Value;

            string strExtension = Path.GetExtension(txtFile.PostedFile.FileName).Replace(".", "");

            if (!String.IsNullOrEmpty(FileFilter) && Strings.InStr("," + FileFilter.ToLower(), "," + strExtension.ToLower(), 0) == 0)
            {
                // trying to upload a file not allowed for current filter
                lblMessage.Text = string.Format(Localization.GetString("UploadError", this.LocalResourceFile), FileFilter, strExtension);
            }
            else
            {
                lblMessage.Text = FileSystemUtils.UploadFile(ParentFolderName.Replace("/", "\\"), txtFile.PostedFile, false);
            }

            if (lblMessage.Text == string.Empty)
            {
                cboFiles.Visible  = true;
                cmdUpload.Visible = _ShowUpLoad;
                txtFile.Visible   = false;
                cmdSave.Visible   = false;
                cmdCancel.Visible = false;

                DirectoryInfo Root = new DirectoryInfo(ParentFolderName);
                cboFiles.Items.Clear();
                cboFiles.DataSource = GetFileList(false);
                cboFiles.DataBind();

                string FileName = txtFile.PostedFile.FileName.Substring(txtFile.PostedFile.FileName.LastIndexOf("\\") + 1);
                if (cboFiles.Items.FindByText(FileName) != null)
                {
                    cboFiles.Items.FindByText(FileName).Selected = true;
                }
            }
        }
        protected void cmdSave_Click(object sender, EventArgs e)
        {
            string CurrentTime = DateTime.Now.ToString("_yyyy_MM_dd_HH_mm_ss");

            // if no file is selected exit
            if (txtFile.PostedFile.FileName == "")
            {
                return;
            }

            string ParentFolderName;

            if (PortalSettings.ActiveTab.ParentId == PortalSettings.SuperTabId)
            {
                ParentFolderName = Globals.HostMapPath;
            }
            else
            {
                ParentFolderName = PortalSettings.HomeDirectoryMapPath;
            }
            ParentFolderName += Folder;

            string strExtension   = Path.GetExtension(txtFile.PostedFile.FileName).Replace(".", "");
            string fullFileFilter = "," + FileFilter.ToLower();

            if (!String.IsNullOrEmpty(FileFilter) && !fullFileFilter.Contains("," + strExtension.ToLower()))
            {
                // trying to upload a file not allowed for current filter
                lblMessage.Text = string.Format(Localization.GetString("UploadError", this.LocalResourceFile), FileFilter, strExtension);
            }
            else
            {
                lblMessage.Text = FileSystemUtils.UploadFileWithTime(CurrentTime, ParentFolderName.Replace("/", "\\"), txtFile.PostedFile, false);
            }

            if (lblMessage.Text == String.Empty)
            {
                lblFileName.Text = txtFile.PostedFile.FileName.Substring(txtFile.PostedFile.FileName.LastIndexOf("\\") + 1);
                int dotIndex = lblFileName.Text.LastIndexOf(".");
                lblFileName.Text = lblFileName.Text.Substring(0, dotIndex) + CurrentTime + lblFileName.Text.Substring(dotIndex);
                FileController fileCont = new FileController();
                FileInfo       file     = fileCont.GetFile(lblFileName.Text, _objPortal.PortalID, Folder);
                lblFileID.Text = file.FileId.ToString();
            }
        }
        protected void cmdSave_Click(object sender, EventArgs e)
        {
            //if (CanUpload)
            //{
            string strUnzipFileIDs   = "";
            string strUnzipFileNames = "";
            string CurrentTime       = DateTime.Now.ToString("_yyyy_MM_dd_HH_mm_ss");

            // if no file is selected exit
            if (txtFile.PostedFile.FileName == "")
            {
                return;
            }

            string ParentFolderName;

            if (PortalSettings.ActiveTab.ParentId == PortalSettings.SuperTabId)
            {
                ParentFolderName = Globals.HostMapPath;
            }
            else
            {
                ParentFolderName = PortalSettings.HomeDirectoryMapPath;
            }
            ParentFolderName += Folder;

            string strExtension   = Path.GetExtension(txtFile.PostedFile.FileName).Replace(".", "");
            string fullFileFilter = "," + FileFilter.ToLower();

            if (!String.IsNullOrEmpty(FileFilter) && !fullFileFilter.Contains("," + strExtension.ToLower()) && strExtension.ToLower() != "zip")
            {
                // trying to upload a file not allowed for current filter
                lblMessage.Text = string.Format(Localization.GetString("UploadError", this.LocalResourceFile), FileFilter, strExtension);
            }
            else
            {
                lblMessage.Text        = FileSystemUtils.UploadFileWithTime(CurrentTime, ParentFolderName.Replace("/", "\\"), txtFile.PostedFile, true, out strUnzipFileNames, out strUnzipFileIDs);
                lblUnzipFileNames.Text = strUnzipFileNames;
                lblUnzipFileIDs.Text   = strUnzipFileIDs;
            }

            if (lblMessage.Text == String.Empty)
            {
                lblFileName.Text = txtFile.PostedFile.FileName.Substring(txtFile.PostedFile.FileName.LastIndexOf("\\") + 1);
                int dotIndex = lblFileName.Text.LastIndexOf(".");
                lblFileName.Text = lblFileName.Text.Substring(0, dotIndex) + CurrentTime + lblFileName.Text.Substring(dotIndex);
            }
            //}
            //else
            //{
            //    lblFileName.Text = "Bạn không có quyền upload file tại đây!";
            //}
        }
示例#4
0
        public bool Save()
        {
            var fileName     = _alias + ".cshtml";
            var fullFilePath = IOHelper.MapPath(BasePath + fileName);

            //return the link to edit the file if it already exists
            if (File.Exists(fullFilePath))
            {
                _returnUrl = string.Format(EditViewFile + "?file={0}", HttpUtility.UrlEncode(ParentFolderName.EnsureEndsWith('/') + fileName));
                return(true);
            }

            //create the file
            using (var sw = File.CreateText(fullFilePath))
            {
                WriteTemplateHeader(sw);
            }

            // Create macro?
            if (ParentID == 1)
            {
                var name = fileName
                           .Substring(0, (fileName.LastIndexOf('.') + 1)).Trim('.')
                           .SplitPascalCasing().ToFirstUpperInvariant();
                var m = cms.businesslogic.macro.Macro.MakeNew(name);
                m.ScriptingFile = BasePath + fileName;
            }

            _returnUrl = string.Format(EditViewFile + "?file={0}", HttpUtility.UrlEncode(ParentFolderName.EnsureEndsWith('/') + fileName));
            return(true);
        }
示例#5
0
        public bool Save()
        {
            var pipesIndex = _alias.IndexOf("|||", System.StringComparison.Ordinal);
            var template   = _alias.Substring(0, pipesIndex).Trim();
            var fileName   = _alias.Substring(pipesIndex + 3, _alias.Length - pipesIndex - 3) + ".cshtml";

            var fullFilePath = IOHelper.MapPath(BasePath + fileName);

            //return the link to edit the file if it already exists
            if (File.Exists(fullFilePath))
            {
                _returnUrl = string.Format(EditViewFile + "?file={0}", HttpUtility.UrlEncode(ParentFolderName.EnsureEndsWith('/') + fileName));
                return(true);
            }

            //create the file
            using (var sw = File.CreateText(fullFilePath))
            {
                using (var templateFile = File.OpenText(IOHelper.MapPath(SystemDirectories.Umbraco + "/PartialViews/Templates/" + template)))
                {
                    var templateContent = templateFile.ReadToEnd();
                    sw.Write(templateContent);
                }
            }

            // Create macro?
            if (ParentID == 1)
            {
                var name = fileName
                           .Substring(0, (fileName.LastIndexOf('.') + 1)).Trim('.')
                           .SplitPascalCasing().ToFirstUpperInvariant();
                var m = cms.businesslogic.macro.Macro.MakeNew(name);
                m.ScriptingFile = BasePath + fileName;
            }

            _returnUrl = string.Format(EditViewFile + "?file={0}", HttpUtility.UrlEncode(ParentFolderName.EnsureEndsWith('/') + fileName));
            return(true);
        }