【问题标题】:using file upload control to upload a file and pass the file to an object/web service使用文件上传控件上传文件并将文件传递给对象/Web服务
【发布时间】:2015-01-21 15:56:38
【问题描述】:

我想在网页上附加一个文件并将其保存在 TFS 中。

我正在使用 asp.net fileupload 控件来保存文件。 谁能告诉我如何从fileupload插入访问的文件 控制到 tfs 中?

这是我的代码:

   protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e)
   {
       FileUpload fu = (FileUpload)FormView1.FindControl("FileUpLoad1");

        if (fu.HasFile)
        {

       // I want to know the code changes to the line below :               
        workitem.Attachments.Add(new Attachment("file accessed from file upload", "comment"));
        }
       }

【问题讨论】:

    标签: c# asp.net tfs webforms tfs-sdk


    【解决方案1】:

    试试这个,它在 aspx.vb 世界中对我有用 :o) Rgds, 马夫。

     Dim objFSO, objFolder
     objFolder = "D:\dump\"
     objFSO = CreateObject("Scripting.FileSystemObject")
     objFSO.CreateFolder(objFolder)
     System.IO.Directory.SetCurrentDirectory(objFolder.ToString)
     Dim physicalFolder = System.IO.Directory.GetCurrentDirectory().ToString
     Dim fileName As String = System.IO.Path.GetFileNameWithoutExtension(FileUploadControl.FileName)
     Dim extension As String = System.IO.Path.GetExtension(FileUploadControl.FileName)
     FileUploadControl.PostedFile.SaveAs(System.IO.Path.Combine(physicalFolder, _ 
      fileName + extension))
    

    【讨论】:

    • 您是在此处将文件保存到您的 D 盘吗?我想传递从 fileupload 控件访问的文件并将文件发送到对象
    • 您必须先将文件保存在本地,然后将其传递给 TFS。
    • 我正在使用一个将部署到服务器的 Web 应用程序。所以你的意思是把它保存在服务器上,然后从服务器访问文件?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-09
    • 1970-01-01
    • 2017-07-28
    • 1970-01-01
    • 2011-08-16
    • 2017-12-14
    • 2018-05-20
    相关资源
    最近更新 更多