0

我正在尝试创建一个函数,该函数将通过网络表单在 TFS 中插入多个带有工作项的附件。我最初的想法是创建一个列表,其中包含上传到网络表单的附件的文件路径,然后将附件添加到工作项:

foreach (string attachment in attachmentList)
            {
                Task.Attachments.Add(new Attachment(attachment));
            }

问题是我似乎无法填充列表。我已经尝试使用下面的代码,但是 UploadButton_click 函数似乎没有将路径添加到附件列表,我不知道为什么。

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.";
        }
    }  
4

1 回答 1

0

终于想通了。在这种情况下,列表必须是静态的

static List<string> attachmentList = new List<string>();
于 2013-07-31T07:07:51.470 回答