Clipboard and CSV (CommaSeparatedValue) does not work

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

I am simply trying to write CSV data to the the clipboard. The code
below is not working. Any suggestions?

Dim data As New DataObject
Dim ms As New MemoryStream
Dim sw As New StreamWriter(ms)

sw.Write("Tom")
sw.Write(",")
sw.Write("Jones")
sw.Write(",")
sw.Write(100)
sw.WriteLine()
sw.Write(Chr(0))
sw.Close()

data.SetData(DataFormats.CommaSeparatedValue, ms)
Clipboard.SetDataObject(data, False)

ms.Close()

THANKS
Bob
 
This seemed to work for me.

Dim data As New DataObject
Dim sb As New System.Text.StringBuilder
sb.Append("Tom")
sb.Append(",")
sb.Append("Jones")
sb.Append(",")
sb.Append("100")
sb.Append(Environment.NewLine)
'sb.Append(Chr(0))
data.SetData(DataFormats.CommaSeparatedValue, sb.ToString())
Clipboard.SetDataObject(data)

To retrieve it:
Me.TextBox1.Text =
Clipboard.GetDataObject().GetData(DataFormats.CommaSeparatedValue).ToString(
)

=================================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools
 
Clay thanks for the help. I tried your code and my clipboard viewer
displays the CSV data just fine. However, I can not past this into
Excel, Word, or Notepad. I am using CSV to alow some records to be
copied to other applications. Any further suggestions?

Again thanks,
Bob
 
Back
Top