0

Is there any way to turn multiple paths from a DB field into separate href links? eg:

c:\MyPath\SomeFile.pdf;c:\MyPath\AnotherFile.pdf;c:\MyPath\LastFile.pdf

I'm able to program a single path above into a link but the SQL DB I'm using could have up to 3 separate paths to files in it.

So for example I can turn this:

c:\MyPath\SomeFile.pdf

Into this link (and make it clickable):

\\1.1.1.1\c$\MyPath\SomeFile.pdf

I'm currently able to do this by creating a few variables to hold the path and the data from the field:

string UNCPath = "\\\\1.1.1.1\\c$\\";
string PathToFile = (dgv[e.ColumnIndex, e.RowIndex].Value.ToString());
System.Diagnostics.Process.Start(temp1 + temp2);

Some additional notes on the above:

  • I also change the colon to dollar
  • Of course the IP and path etc are fake

The problem is that I'm not sure what to do if the field has multiple fields.

I'm thinking a right click menu that shows all 3 (or 2 or 1) paths and make them clickable.

Or I'd have to open another form page listing them....similar to the above line.

These methods don't seem like a very good approach to me.

Is there any other decent way to do this?

stakx - no longer contributing
  • 83,039
  • 20
  • 168
  • 268
Chris
  • 39
  • 2
  • 2
  • 6
  • 2
    This has nothing to do with databases. It doesn't matter where your string comes from. – usr Jun 19 '12 at 15:37
  • Right clic and show a context-menu with the different items seems to be appropiate. Showing a new form may not help you on improving user's experience if your aim is to just let them open the files. [This other SO](http://stackoverflow.com/questions/1718389/right-click-context-menu-for-datagrid) resource might help you. – Luis Quijada Jun 19 '12 at 16:38
  • I was thinking the same and thought string.split and a for or foreach would work but for some reason it isn't:;string[] paths = myPaths.Split(';');' 'foreach (string path in paths)' '{' '//MessageBox.Show(path);' 'm.MenuItems.Add(new MenuItem(path));' '}' – Chris Jun 19 '12 at 17:49
  • I was able to get it to work but am not sure how to access the file name itself. I tried a few things://MessageBox.Show(m.ToString()); ////MessageBox.Show(m.Tag.ToString()); //MessageBox.Show(m.Name.ToString()); //MessageBox.Show(m.MenuItems.ToString()); ////MessageBox.Show(m.MdiListItem.ToString()); // MessageBox.Show(m.Name); //MessageBox.Show(m.MdiListItem.Text); //MessageBox.Show(m.ToString()); //MessageBox.Show(m.MenuItems.ToString()); Does anyone have any thoughts? Thanks, – Chris Jun 19 '12 at 21:27

0 Answers0