dnn 添加图片

 public string fileUpload()         {             if (fuPhoto.PostedFile != null && fuPhoto.PostedFile.ContentLength > 0)             {                 int _ModuleID = (this.Parent.TemplateControl as View).ModuleId;

                string ext = System.IO.Path.GetExtension(fuPhoto.PostedFile.FileName).ToLower();                 if (ext != ".jpg" && ext != ".jpeg" && ext != ".bmp" && ext != ".gif")                 {                     return "";                 }                 string filename = "photo" + DateTime.Now.ToString("yyyyMMddHHmmss") + ext;                 string path = "upload/" + _ModuleID + "/photo/" + UserId + "/";

                var dnn_path =  DotNetNuke.Services.FileSystem.FolderManager.Instance.AddFolder(PortalId,path);

                var dnn_file= DotNetNuke.Services.FileSystem.FileManager.Instance.AddFile(dnn_path, filename, fuPhoto.PostedFile.InputStream);

                return dnn_file.FileId.ToString();             }             else             {                 //do some thing;                 return "";             }         }

 

 

public static void UpdateProfilePhoto(UserInfo user, string photoPath) {  DotNetNuke.Services.FileSystem.IFolderInfo fi = DotNetNuke.Services.FileSystem.FolderManager.Instance.GetUserFolder(user);  DotNetNuke.Services.FileSystem.IFileInfo file;

 using (FileStream localFileStream = new FileStream(photoPath, FileMode.Open))  {  file = DotNetNuke.Services.FileSystem.FileManager.Instance.AddFile(fi, "profilepicture" + user.UserID.ToString() + ".jpg", localFileStream);  user.Profile["Photo"] = file.FileId;  UserController.UpdateUser(user.PortalID, user);  } }

posted @ 2015-03-27 19:44  王鹏飛  阅读(267)  评论(0编辑  收藏  举报