G
Guest
I have the following VB.net Class/Function that I call from an ASP.net page:
Public Class MyTestClass
Public Function embedHyperlink(ByVal fileID As Integer, ByVal fileName
As String) As String
'Create a New Instance of the HyperLink Control
Dim createHyperLink As New System.Web.UI.WebControls.HyperLink
'Create an Instance of the ClipBoard Object
Dim objClipboard As System.Windows.Forms.Clipboard
Dim sBuildHyperLink As String
Try
'Set the Properties of the HyperLink Control
createHyperLink.ID = "EmbeddedHyperLink"
createHyperLink.NavigateUrl =
"http://www.someDomain.com/docPage.aspx?x=" & fileID
createHyperLink.Text = fileName
'Build HTML HyperLink String
sBuildHyperLink = "<a href=" & createHyperLink.NavigateUrl & ">"
& createHyperLink.Text & "</a>"
'Write HyperLink to Clip Board
objClipboard.SetDataObject(sBuildHyperLink, True)
Return sBuildHyperLink
Catch ex As Exception
Throw
Finally
createHyperLink = Nothing
objClipboard = Nothing
sBuildHyperLink = Nothing
End Try
End Function
End Class
When I get to the line "objClipboard.SetDataObject(sBuildHyperLink, True)",
that writes to the Windows Clipboard I get the following error and I don’t
know why:
Server Error in '/MyTestWeb' Application.
________________________________________
The current thread must set to Single Thread Apartment (STA) mode before OLE
calls can be made. Ensure that your Main function has STAThreadAttribute
marked on it.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details: System.Threading.ThreadStateException: The current thread
must set to Single Thread Apartment (STA) mode before OLE calls can be made.
Ensure that your Main function has STAThreadAttribute marked on it.
Can someone tell me what I’m doing wrong?
Thanks
Public Class MyTestClass
Public Function embedHyperlink(ByVal fileID As Integer, ByVal fileName
As String) As String
'Create a New Instance of the HyperLink Control
Dim createHyperLink As New System.Web.UI.WebControls.HyperLink
'Create an Instance of the ClipBoard Object
Dim objClipboard As System.Windows.Forms.Clipboard
Dim sBuildHyperLink As String
Try
'Set the Properties of the HyperLink Control
createHyperLink.ID = "EmbeddedHyperLink"
createHyperLink.NavigateUrl =
"http://www.someDomain.com/docPage.aspx?x=" & fileID
createHyperLink.Text = fileName
'Build HTML HyperLink String
sBuildHyperLink = "<a href=" & createHyperLink.NavigateUrl & ">"
& createHyperLink.Text & "</a>"
'Write HyperLink to Clip Board
objClipboard.SetDataObject(sBuildHyperLink, True)
Return sBuildHyperLink
Catch ex As Exception
Throw
Finally
createHyperLink = Nothing
objClipboard = Nothing
sBuildHyperLink = Nothing
End Try
End Function
End Class
When I get to the line "objClipboard.SetDataObject(sBuildHyperLink, True)",
that writes to the Windows Clipboard I get the following error and I don’t
know why:
Server Error in '/MyTestWeb' Application.
________________________________________
The current thread must set to Single Thread Apartment (STA) mode before OLE
calls can be made. Ensure that your Main function has STAThreadAttribute
marked on it.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details: System.Threading.ThreadStateException: The current thread
must set to Single Thread Apartment (STA) mode before OLE calls can be made.
Ensure that your Main function has STAThreadAttribute marked on it.
Can someone tell me what I’m doing wrong?
Thanks