zoukankan      html  css  js  c++  java
  • SharePoint 2010 编程上传文档

    protected void btnUpload_Click(object sender, EventArgs e)
            {
                Boolean FileOK = false;
                Boolean FileSaved = false;
                String accountName = SPContext.Current.Web.CurrentUser.LoginName;
                string fileNameWithoutExtension = GetFileNameFromAccountName(accountName);
                String FileExtension = string.Empty;
    
                SPWeb web = SPContext.Current.Web;
    
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                        using (SPSite currentSite = new SPSite(web.Site.Url))
                        {             
                            using (SPWeb currentWeb = currentSite.OpenWeb())
                            {
    
                                if (Upload.HasFile)
                                {
                                        FileExtension = Path.GetExtension(Upload.FileName.ToString()).ToLower();
                                        String[] allowedExtensions = { ".png", ".jpeg", ".jpg", ".gif" };
                                        for (int i = 0; i < allowedExtensions.Length; i++)
                                        {
                                                if (FileExtension == allowedExtensions[i])
                                                {
                                                        FileOK = true;
                                                        break;
                                                }
                                        }
                                    }
    
                                if (FileOK)
                                {
                                        try
                                        {
    
                                                currentWeb.AllowUnsafeUpdates = true;
                                                SPSecurity.CatchAccessDeniedException = false;
    
                                                SPList listePictureUpload = currentWeb.GetList(SPUtility.ConcatUrls(currentWeb.Url, "User Photos"));
                                                SPFile itemPictureUpload = currentWeb.Files.Add(listePictureUpload.RootFolder.Url + "/" + Upload.FileName.Remove(Upload.FileName.Length -                                 FileExtension.Length) + fileNameWithoutExtension + FileExtension, Upload.FileBytes, true);
                                                //SPFile itemPictureUpload = listePictureUpload.RootFolder.Files.Add(Upload.FileName.Remove(Upload.FileName.Length - FileExtension.Length) +                                 fileNameWithoutExtension + FileExtension, Upload.FileBytes, true);
                                                currentWeb.AllowUnsafeUpdates = false;
                                        }
                                 }
                          }
                    }
        
             });
    
    }
  • 相关阅读:
    【XilinxVDMA模块学习】00开始
    【USBHID在STM32上的实现】00开始
    【XilinxZYNQ ucosiii的移植与开发】00开始
    【XilinxLVDS读写功能实现】00开始
    算法与数据结构
    页面进度条
    前端SEO优化
    正则表达式(Regular Expression)
    对网页中层的固定
    c#排序算法
  • 原文地址:https://www.cnblogs.com/ahghy/p/2984028.html
Copyright © 2011-2022 走看看