SuperDoc
SuperDoc

Reputation: 43

Not getting all URL's with loop

I am looping throw my docTab.Rows which is a Dataset Table connected to a method which is returning six results.

What I am trying to do is to loop throw does results get the field from my table in which I am interested most URL in my case. and then set this URL as a path so that I can copy all the files that I need

    foreach (var row in docTab.Rows)
    {   
        var sourceFile = "//ch-s-0001535/G/inetpub/DocAddWeb/DataSource/"+docTab.Rows[0]["URL"].ToString();
        string targetPath = rootFolderAbsolutePath;
        File.Copy(sourceFile, rootFolderAbsolutePath+Path.GetFileName(sourceFile),overwrite:true);
    }

My issue is that I only get 1 file and always the same , never seen the other six even do my loop goes throw 6 times

Upvotes: 0

Views: 34

Answers (2)

sowjanya attaluri
sowjanya attaluri

Reputation: 911

Replace foreach 'var' to 'DataRow'. Then it will loop through all rows of dataset table

foreach (DataRow row in docTab.Rows)
{
   var sourceFile = "//ch-s-0001535/G/inetpub/DocAddWeb/DataSource/" + row["URL"].ToString();
      //Your code
}

Upvotes: 1

Chaitanya
Chaitanya

Reputation: 171

 foreach (DataRow row in docTab.Rows)
 {
    var sourceFile = "//ch-s-0001535/G/inetpub/DocAddWeb/DataSource/" + row["URL"].ToString();
          //Your code
 }

Upvotes: 1

Related Questions