private Resource_FilesStatus UploadFile(HttpContext context, HttpPostedFile Httpfiles)
        {
            Resource_FilesStatus Resource = new Resource_FilesStatus();

            if (Httpfiles != null && Httpfiles.ContentLength > 0)
            {
                //To verify that if the suffix name of the uploaded files meets the DNN HOST requirements
                Boolean retValue = FileSystemUtils.CheckValidFileName(Httpfiles.FileName);
                if (retValue)
                {
                    //构造文件的存放目录
                    String FileName       = Httpfiles.FileName;
                    String tempName       = WebHelper.GetStringParam(context.Request, "id", "");
                    String Extension      = Path.GetExtension(FileName);
                    String leftName       = FileName.Replace(Extension, "");
                    String FileWebPath    = String.Format("{0}PowerForms/Multiplefiles/{1}/{2}/{3}-[{4}]{5}", PortalSettings.HomeDirectory, ModuleId, DateTime.Now.ToString("yyyyMMdd"), leftName, tempName, Extension);
                    String FileServerPath = context.Request.MapPath(FileWebPath);

                    //构造文件对象
                    FileInfo Savefile = new FileInfo(FileServerPath);
                    //文件夹构造
                    if (!Savefile.Directory.Exists)
                    {
                        Savefile.Directory.Create();
                    }
                    //文件是否存在||存在的话需要重新构造名称filename_2.txt
                    Int32 FileIndex = 2;
                    while (Savefile.Exists)
                    {
                        FileWebPath    = String.Format("{0}PowerForms/Multiplefiles/{1}/{2}/{3}_{4}-[{5}]{6}", PortalSettings.HomeDirectory, ModuleId, DateTime.Now.ToString("yyyyMMdd"), leftName, FileIndex, tempName, Extension);
                        FileServerPath = context.Request.MapPath(FileWebPath);
                        Savefile       = new FileInfo(FileServerPath);
                        FileIndex++;
                    }
                    //构造需要返回的信息
                    Resource.name = FileName;
                    Resource.size = Httpfiles.ContentLength;
                    Resource.url  = FileWebPath;
                    Resource.type = Httpfiles.ContentType;


                    //构造指定存储路径
                    Httpfiles.SaveAs(Savefile.FullName);
                }
            }
            else
            {
                //文件大小为空或者是0
            }

            return(Resource);
        }
        /// <summary>
        /// 获取Form传值
        /// </summary>
        /// <param name="fieldItem"></param>
        /// <returns></returns>
        public static String GetWebFormValue(SettingEntity fieldItem, basePortalModule bpm)
        {
            String WebFormValue = String.Empty;

            //创建控件的Name和ID
            ControlHelper ControlItem = new ControlHelper(bpm.ModuleId);
            String        ControlName = ControlItem.ViewControlName(fieldItem);
            String        ControlID   = ControlItem.ViewControlID(fieldItem);

            if (fieldItem.ControlType == EnumControlType.CheckBox.ToString())
            {
                WebFormValue = WebHelper.GetStringParam(HttpContext.Current.Request, ControlName, "");
                WebFormValue = !String.IsNullOrEmpty(WebFormValue) && WebFormValue == "on" ? "true" : "false";
            }
            else if (fieldItem.ControlType == EnumControlType.FileUpload.ToString())
            {
                HttpPostedFile hpFile = HttpContext.Current.Request.Files[ControlName];
                //To verify that if the suffix name of the uploaded files meets the DNN HOST requirements
                Boolean retValue = FileSystemUtils.CheckValidFileName(hpFile.FileName);
                if (retValue)
                {
                    if (hpFile != null && hpFile.ContentLength > 0)
                    {
                        WebFormValue = String.Format("Url://{0}", FileSystemUtils.UploadFile(hpFile, bpm));                                                            //存放到目录中,并返回
                    }
                }
            }
            else if (fieldItem.ControlType == EnumControlType.Urls.ToString())
            {
                String ClientName = GetRichUrlsName(fieldItem);
                if (bpm.HttpContext.Items.Contains(ClientName))
                {
                    WebFormValue = Convert.ToString(bpm.HttpContext.Items[ClientName]);
                }
            }
            else
            {
                WebFormValue = WebHelper.GetStringParam(HttpContext.Current.Request, ControlName, "");
            }
            return(WebFormValue);
        }
        /// <summary>
        /// 多文件上传之暂存办法
        /// </summary>
        public void SaveMultiplefiles()
        {
            Dictionary <String, Object> jsonFils = new Dictionary <string, Object>();

            String ControlName = WebHelper.GetStringParam(Request, "ControlName", "");

            if (!String.IsNullOrEmpty(ControlName))
            {
                if (Request.Files.Count > 0 && Request.Files[ControlName] != null)
                {
                    HttpPostedFile Httpfiles = Request.Files[ControlName];
                    if (Httpfiles != null && Httpfiles.ContentLength > 0)
                    {
                        //To verify that if the suffix name of the uploaded files meets the DNN HOST requirements
                        bool retValue = FileSystemUtils.CheckValidFileName(Httpfiles.FileName);
                        if (retValue)
                        {
                            //构造文件的存放目录
                            String FileName       = Httpfiles.FileName;
                            String FileWebPath    = String.Format("{0}PowerForms/Multiplefiles/{1}/{2}/{3}", PortalSettings.HomeDirectory, ModuleId, DateTime.Now.ToString("yyyyMMdd"), Httpfiles.FileName);
                            String FileServerPath = MapPath(FileWebPath);
                            String Extension      = Path.GetExtension(FileServerPath);
                            String leftName       = FileName.Replace("." + Extension, "");
                            //构造文件对象
                            FileInfo Savefile = new FileInfo(FileServerPath);
                            //文件夹构造
                            if (!Savefile.Directory.Exists)
                            {
                                Savefile.Directory.Create();
                            }
                            //文件是否存在||存在的话需要重新构造名称filename_2.txt
                            Int32 FileIndex = 2;
                            while (Savefile.Exists)
                            {
                                FileWebPath    = String.Format("{0}PowerForms/Multiplefiles/{1}/{2}/{3}_{4}.{5}", PortalSettings.HomeDirectory, ModuleId, DateTime.Now.ToString("yyyyMMdd"), leftName, FileIndex, Extension);
                                FileServerPath = MapPath(FileWebPath);
                                Savefile       = new FileInfo(FileServerPath);
                                FileIndex++;
                            }



                            //构造指定存储路径
                            Httpfiles.SaveAs(Savefile.FullName);
                        }
                    }
                    else
                    {
                        //文件大小为空或者是0
                    }
                }
                else
                {
                    //没有上传文件或
                }
            }
            else
            {
                //控件没传过来
            }

            //转换数据为json
            JavaScriptSerializer jsSerializer = new JavaScriptSerializer();

            Response.Clear();
            Response.Write(jsSerializer.Serialize(jsonFils));
            Response.End();
        }
예제 #4
0
        // Upload entire file
        private void UploadWholeFile(HttpContext context, List <Resource_FilesStatus> statuses)
        {
            for (int i = 0; i < context.Request.Files.Count; i++)
            {
                var file = context.Request.Files[i];

                if (file != null && !String.IsNullOrEmpty(file.FileName) && file.ContentLength > 0)
                {
                    //To verify that if the suffix name of the uploaded files meets the DNN HOST requirements
                    Boolean retValue = FileSystemUtils.CheckValidFileName(file.FileName);
                    if (retValue)
                    {
                        DNNGo_PowerForms_Files PhotoItem = new DNNGo_PowerForms_Files();

                        PhotoItem.ModuleId = WebHelper.GetIntParam(context.Request, "ModuleId", 0);
                        PhotoItem.PortalId = WebHelper.GetIntParam(context.Request, "PortalId", 0);


                        PhotoItem.FileName = file.FileName;
                        PhotoItem.FileSize = file.ContentLength / 1024;
                        PhotoItem.FileMate = FileSystemUtils.GetContentType(Path.GetExtension(PhotoItem.FileName).Replace(".", ""));

                        PhotoItem.FileExtension = System.IO.Path.GetExtension(PhotoItem.FileName).Replace(".", "");
                        PhotoItem.Name          = System.IO.Path.GetFileName(file.FileName).Replace(Path.GetExtension(PhotoItem.FileName), "");
                        PhotoItem.Status        = (Int32)EnumFileStatus.Approved;

                        try
                        {
                            if (("png,gif,jpg,jpeg,bmp").IndexOf(PhotoItem.FileExtension) >= 0)
                            {
                                //图片的流
                                Image image = Image.FromStream(file.InputStream);
                                PhotoItem.ImageWidth  = image.Width;
                                PhotoItem.ImageHeight = image.Height;

                                PhotoItem.Exif = Common.Serialize <EXIFMetaData.Metadata>(new EXIFMetaData().GetEXIFMetaData(image));
                            }
                        }
                        catch
                        {
                        }

                        PhotoItem.LastTime = xUserTime.UtcTime();
                        PhotoItem.LastIP   = WebHelper.UserHost;
                        PhotoItem.LastUser = UserInfo.UserID;


                        //将文件存储的路径整理好
                        String fileName = System.IO.Path.GetFileName(file.FileName).Replace("." + PhotoItem.FileExtension, ""); //文件名称
                        String WebPath  = String.Format("PowerForms/uploads/{0}/{1}/{2}/", xUserTime.UtcTime().Year, xUserTime.UtcTime().Month, xUserTime.UtcTime().Day);
                        //检测文件存储路径是否有相关的文件
                        FileInfo fInfo = new FileInfo(HttpContext.Current.Server.MapPath(String.Format("{0}{1}{2}.{3}", PortalSettings.HomeDirectory, WebPath, fileName, PhotoItem.FileExtension)));

                        //检测文件夹是否存在
                        if (!System.IO.Directory.Exists(fInfo.Directory.FullName))
                        {
                            System.IO.Directory.CreateDirectory(fInfo.Directory.FullName);
                        }
                        else
                        {
                            Int32 j = 1;
                            while (fInfo.Exists)
                            {
                                //文件已经存在了
                                fileName = String.Format("{0}_{1}", PhotoItem.Name, j);
                                fInfo    = new FileInfo(HttpContext.Current.Server.MapPath(String.Format("{0}{1}{2}.{3}", PortalSettings.HomeDirectory, WebPath, fileName, PhotoItem.FileExtension)));
                                j++;
                            }
                        }

                        PhotoItem.FilePath = String.Format("{0}{1}.{2}", WebPath, fileName, PhotoItem.FileExtension);
                        PhotoItem.FileName = String.Format("{0}.{1}", fileName, PhotoItem.FileExtension);
                        try
                        {
                            if (!fInfo.Directory.Exists)
                            {
                                fInfo.Directory.Create();

                                // FileSystemUtils.AddFolder(PortalSettings, String.Format("{0}DNNGo_PhotoAlbums/{0}/{1}/"), String.Format("{0}DNNGo_PhotoAlbums/{0}/{1}/"), (int)DotNetNuke.Services.FileSystem.FolderController.StorageLocationTypes.InsecureFileSystem);
                            }

                            //构造指定存储路径
                            file.SaveAs(fInfo.FullName);
                            //FileSystemUtils.AddFile(PhotoItem.FileName, PhotoItem.PortalId, String.Format("DNNGo_PhotoAlbums\\{0}\\{1}\\", PhotoItem.ModuleId, PhotoItem.AlbumID), PortalSettings.HomeDirectoryMapPath, PhotoItem.FileMeta);
                        }
                        catch (Exception ex)
                        {
                        }

                        //给上传的相片设置初始的顺序
                        QueryParam qp = new QueryParam();
                        qp.ReturnFields = qp.Orderfld = DNNGo_PowerForms_Files._.Sort;
                        qp.OrderType    = 1;
                        qp.Where.Add(new SearchParam(DNNGo_PowerForms_Files._.PortalId, PhotoItem.PortalId, SearchType.Equal));
                        PhotoItem.Sort = Convert.ToInt32(DNNGo_PowerForms_Files.FindScalar(qp)) + 2;
                        Int32 PhotoId = PhotoItem.Insert();



                        statuses.Add(new Resource_FilesStatus(PhotoItem, PortalSettings, ModulePath));
                    }
                }
            }
        }
예제 #5
0
        /// <summary>
        /// 获取Form传值
        /// </summary>
        /// <param name="fieldItem"></param>
        /// <returns></returns>
        public String GetWebFormValue(DNNGo_PowerForms_Field fieldItem)
        {
            String WebFormValue = String.Empty;

            //创建控件的Name和ID
            TemplateFormat xf          = new TemplateFormat(this);
            String         ControlName = xf.ViewControlName(fieldItem);
            String         ControlID   = xf.ViewControlID(fieldItem);


            if (fieldItem.FieldType == (Int32)EnumViewControlType.CheckBox)
            {
                WebFormValue = WebHelper.GetStringParam(Request, ControlName, "");
                WebFormValue = !String.IsNullOrEmpty(WebFormValue) && WebFormValue == "on" ? "true" : "false";
            }
            else if (fieldItem.FieldType == (Int32)EnumViewControlType.FileUpload)
            {
                if (Request.Files != null && Request.Files.Count > 0)
                {
                    HttpPostedFile hpFile = Request.Files.Get(ControlName);
                    if (hpFile != null && hpFile.ContentLength > 0)
                    {
                        //To verify that if the suffix name of the uploaded files meets the DNN HOST requirements
                        Boolean retValue = FileSystemUtils.CheckValidFileName(hpFile.FileName);
                        if (retValue)
                        {
                            WebFormValue = String.Format("Url://{0}", FileSystemUtils.UploadFile(hpFile, this));//存放到目录中,并返回
                        }
                    }
                }
            }
            else if (fieldItem.FieldType == (Int32)EnumViewControlType.MultipleFilesUpload)
            {
                String WebUploads = WebHelper.GetStringParam(Request, ControlName, "");
                if (!String.IsNullOrEmpty(WebUploads) && WebUploads != "[]")
                {
                    List <Resource_FilesStatus> Uploads = jsSerializer.Deserialize <List <Resource_FilesStatus> >(WebUploads);
                    if (Uploads != null && Uploads.Count > 0)
                    {
                        List <String> fileurls = new List <string>();
                        foreach (var UploadFile in Uploads)
                        {
                            fileurls.Add(String.Format("Url://{0}", FileSystemUtils.CopyFile(UploadFile, this)));
                        }
                        WebFormValue = Common.GetStringByList(fileurls, "<|>");
                    }
                }
            }
            else if (fieldItem.FieldType == (Int32)EnumViewControlType.DropDownList_Country)
            {
                var tempWebFormValue = WebHelper.GetStringParam(HttpContext.Current.Request, ControlName, "");

                var Countrys = new ListController().GetListEntryInfoItems("Country");
                foreach (var Country in Countrys)
                {
                    if (Country.Value == tempWebFormValue)
                    {
                        WebFormValue = Country.Text;
                        break;
                    }
                }
            }
            else
            {
                WebFormValue = WebHelper.GetStringParam(Request, ControlName, "");

                if (!(fieldItem.FieldType == (Int32)EnumViewControlType.RichTextBox))
                {
                    //非富文本框时,需要过滤掉XSS特殊字符
                    WebFormValue = Common.LostXSS(WebFormValue);
                }

                //如果提示的值和输入的值一样的情况,就过滤掉该值 *** 有点争议的地方
                if (WebFormValue == fieldItem.ToolTip && fieldItem.DefaultValue != WebFormValue)
                {
                    WebFormValue = string.Empty;
                }
            }

            return(WebFormValue);
        }