2012-05-07 57 views
0
Need help to convert code from asp control to input type to fetch file name and file bytes. 
Below are the code with asp control. 
ascx Page: 


<asp:FileUpload ID="fileUp" runat="server" EnableViewState="true" class="tdFileUpload" /> 

ascx.cs code is given below 


using (SPSite site = new SPSite(siteId)) 
        { 
         using (SPWeb web = site.OpenWeb(WebId)) 
         { 
          web.AllowUnsafeUpdates = true; 
          string siteurl = SPContext.Current.Web.Url; 
          SPDocumentLibrary library; 
          library = (SPDocumentLibrary)web.Lists["Project_Artifacts"]; /fetches the library list name. 
          library.EnableVersioning = true; 
          library.Update(); 
          SPFolder folder = web.Folders.Add(siteurl + "/Project_Artifacts/" + drpPrj.SelectedItem.Value);//creates a folder of selected item name         

web.Update(); //创建文件夹 folder.Files.Add(folder.Url + “/” + fileUp之后更新网页。 FileName,fileUp.FileBytes); //我想改变CODE这条线按我的新要求我如何得到这两个地方提到这两个值 1. fileUp.FileName 2. fileUp.FileBytes转换代码至c#编码

      folder.Update(); 
          web.Update(); 
    } 
    } 

The current requirement is : 
ascx page code: 


    <div id="FileUpload"> 
                   <input type="file" size="24" id="fileUp" 
                   onchange="getElementById('FileField').value = getElementById('fileUp').value;" /> 
                   <div id="BrowserVisible"> 
                    <input type="text" id="FileField" name="FileField1"/> 

Hope you can figure out the ascx page code difference. 
ascx.cs Page code: 

folder.Files。添加(folder.Url +“/”+ fileUp.FileName,fileUp.FileBytes);

I want to change this line of code with the correct line of code which i am unable to do. 
Please help.Thanks in advance 
+0

嗨我得到了它的答案。替换folder.Files.Add(folder.Url +“/”+ fileUp.FileName,fileUp.FileBytes); to string fileFieldPathValue = Request.Form [“fileFieldPath”]。ToString(); string fileName = System.IO.Path.GetFileName(fileFieldPathValue); var bytes = System.IO.File.ReadAllBytes(fileFieldPathValue); folder.Files.Add(folder.Url +“/”+ fileName,bytes);对我而言,它完美无缺 – missReclusive

回答

0

嗨,我得到了它的答案。 更换

folder.Files.Add(folder.Url + "/" + fileUp.FileName, fileUp.FileBytes); 

string fileFieldPathValue = Request.Form["fileFieldPath"].ToString(); 
string fileName = System.IO.Path.GetFileName(fileFieldPathValue); 
var bytes = System.IO.File.ReadAllBytes(fileFieldPathValue); 
folder.Files.Add(folder.Url + "/" + fileName, bytes); 

对我来说非常完美。