using file upload control to upload a file and pass the file to an object/web service

369 views Asked by At

I would like to attach a file on a web page and save it in TFS.

I am using the asp.net fileupload control to save the file . Can anyone please tell me how I can insert the accessed file from fileupload control into tfs ?

Here is my code :

   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"));
        }
       }
1

There are 1 answers

3
AudioBubble On

Try this, it worked for me in aspx.vb world :o) Rgds, Mav.

 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))