I am trying to create a function that will insert multiple attachments with a work item in TFS through a webform. My initial thought was to create a list that contains the filepaths of the attachments uploaded to the webform, and then add the attachments to the work item with:
foreach (string attachment in attachmentList)
{
Task.Attachments.Add(new Attachment(attachment));
}
The problem is that I can't seem to populate the list. I have tried with the code below, but the UploadButton_click function does not seem to add paths to the attachmentList and I can't figure out why.
List<string> attachmentList = new List<string>();
protected void UploadButton_Click(object sender, EventArgs e)
{
String savePath = @"c:\temp\uploads\";
if (FileUpload1.HasFile)
{
String fileName = FileUpload1.FileName;
savePath += fileName;
FileUpload1.SaveAs(savePath);
UploadStatusLabel.Text = fileName + " was successfully uploaded" ;
Label1.Text +=fileName + ", ";
attachmentList.Add(savePath);
}
else
{
UploadStatusLabel.Text = "You did not specify a file to upload.";
}
}
Finally figured it out. The list has to be static in this case
static List<string> attachmentList = new List<string>();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.