Converting From VB.Net or C# to VBA

  • Thread starter Thread starter Neil
  • Start date Start date
N

Neil

I have some code I need to convert from VB.net to VB or VBA (I will be
using it in Access 2010). The code is to upload a document to a
SharePoint library (using the SharePoint Foundation 2010 Managed COM).
The original code was in C#. I used a C# to VB.Net converter to get it
into VB.Net. Now I need to get it into VB or VBA. Is it possible?

Here is the original C# code (from
http://msdn.microsoft.com/en-us/library/ee956524.aspx):

using System;
using System.IO;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using Microsoft.SharePoint.Client;
// The following directive avoids ambiguity between the
// System.IO.File class and Microsoft.SharePoint.Client.File class.
using ClientOM = Microsoft.SharePoint.Client;
class Program
{
static void Main(string[] args)
{
ClientContext clientContext =
new ClientContext("http://intranet.contoso.com");
using (FileStream fileStream =
new FileStream("NewDocument.docx", FileMode.Open))
ClientOM.File.SaveBinaryDirect(clientContext,
"/Shared Documents/NewDocument.docx", fileStream, true);
}
}

And here is the code after it was converted to VB.Net:

Imports System.IO
Imports DocumentFormat.OpenXml.Packaging
Imports DocumentFormat.OpenXml.Wordprocessing
Imports Microsoft.SharePoint.Client
' The following directive avoids ambiguity between the
' System.IO.File class and Microsoft.SharePoint.Client.File class.
Imports ClientOM = Microsoft.SharePoint.Client
Class Program
Private Shared Sub Main(args As String())
Dim clientContext As New ClientContext("http://intranet.contoso.com")
Using fileStream As New FileStream("NewDocument.docx", FileMode.Open)
ClientOM.File.SaveBinaryDirect(clientContext, "/Shared
Documents/NewDocument.docx", fileStream, True)
End Using
End Sub
End Class

Any idea how this would look in VB or VBA?

Thanks!

Neil
 
Neil said:
I have some code I need to convert from VB.net to VB or VBA (I will be
using it in Access 2010). The code is to upload a document to a
SharePoint library (using the SharePoint Foundation 2010 Managed COM).
The original code was in C#. I used a C# to VB.Net converter to get it
into VB.Net. Now I need to get it into VB or VBA. Is it possible?

Here is the original C# code (from
http://msdn.microsoft.com/en-us/library/ee956524.aspx):

using System;
using System.IO;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using Microsoft.SharePoint.Client;
// The following directive avoids ambiguity between the
// System.IO.File class and Microsoft.SharePoint.Client.File class.
using ClientOM = Microsoft.SharePoint.Client;
class Program
{
static void Main(string[] args)
{
ClientContext clientContext =
new ClientContext("http://intranet.contoso.com");
using (FileStream fileStream =
new FileStream("NewDocument.docx", FileMode.Open))
ClientOM.File.SaveBinaryDirect(clientContext,
"/Shared Documents/NewDocument.docx", fileStream, true);
}
}

And here is the code after it was converted to VB.Net:

Imports System.IO
Imports DocumentFormat.OpenXml.Packaging
Imports DocumentFormat.OpenXml.Wordprocessing
Imports Microsoft.SharePoint.Client
' The following directive avoids ambiguity between the
' System.IO.File class and Microsoft.SharePoint.Client.File class.
Imports ClientOM = Microsoft.SharePoint.Client
Class Program
Private Shared Sub Main(args As String())
Dim clientContext As New ClientContext("http://intranet.contoso.com")
Using fileStream As New FileStream("NewDocument.docx", FileMode.Open)
ClientOM.File.SaveBinaryDirect(clientContext, "/Shared
Documents/NewDocument.docx", fileStream, True)
End Using
End Sub
End Class

Any idea how this would look in VB or VBA?

Thanks!

Neil

I have no idea but you may want to try http://experts-exchange.com. They
may figure it out but you pay for the service.
 
I have some code I need to convert from VB.net to VB or VBA (I will be
using it in Access 2010). The code is to upload a document to a
SharePoint library (using the SharePoint Foundation 2010 Managed COM).
The original code was in C#. I used a C# to VB.Net converter to get it
into VB.Net. Now I need to get it into VB or VBA. Is it possible?

Here is the original C# code (from
http://msdn.microsoft.com/en-us/library/ee956524.aspx):

using System;
using System.IO;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using Microsoft.SharePoint.Client;
// The following directive avoids ambiguity between the
// System.IO.File class and Microsoft.SharePoint.Client.File class.
using ClientOM = Microsoft.SharePoint.Client;
class Program
{
static void Main(string[] args)
{
ClientContext clientContext =
new ClientContext("http://intranet.contoso.com");
using (FileStream fileStream =
new FileStream("NewDocument.docx", FileMode.Open))
ClientOM.File.SaveBinaryDirect(clientContext,
"/Shared Documents/NewDocument.docx", fileStream, true);
}
}

And here is the code after it was converted to VB.Net:

Imports System.IO
Imports DocumentFormat.OpenXml.Packaging
Imports DocumentFormat.OpenXml.Wordprocessing
Imports Microsoft.SharePoint.Client
' The following directive avoids ambiguity between the
' System.IO.File class and Microsoft.SharePoint.Client.File class.
Imports ClientOM = Microsoft.SharePoint.Client
Class Program
Private Shared Sub Main(args As String())
Dim clientContext As New
ClientContext("http://intranet.contoso.com")
Using fileStream As New FileStream("NewDocument.docx",
FileMode.Open)
ClientOM.File.SaveBinaryDirect(clientContext, "/Shared
Documents/NewDocument.docx", fileStream, True)
End Using
End Sub
End Class

Any idea how this would look in VB or VBA?

It could be difficult translating those .NET library
calls into equivalent COM calls.

I say that the easiest way forward us to rewrite the C# console
app above to expose a COM interface and then call that from VBA.

Arne
 
I have no idea but you may want to try http://experts-exchange.com. They
may figure it out but you pay for the service.

E-E is what was used 5-10 years ago. Today it is SO.

But I find it a bit distasteful to suggest other
fora than usenet given that there are usenet groups
where this question could be answered.

Arne
 
Arne said:
E-E is what was used 5-10 years ago. Today it is SO.

But I find it a bit distasteful to suggest other
fora than usenet given that there are usenet groups
where this question could be answered.

Arne

I don't see too many helping him out. Do you? If you find it distasteful
you whiny bitch then help him out or **** off.

TMA
 
Thanks, everyone, for your replies! I actually found another way to
accomplish this that didn't use the SP Foundation COM. So, was able to
write it directly in VBA. Thanks for the input, though. Appreciate it!

Neil
 
I have some code I need to convert from VB.net to VB or VBA (I will be
using it in Access 2010). The code is to upload a document to a
SharePoint library (using the SharePoint Foundation 2010 Managed COM).
The original code was in C#. I used a C# to VB.Net converter to get it
Any idea how this would look in VB or VBA?

Thanks!

Neil

You could do it by building a COM interop library to wrap the .NET
sharepoint stuff as COM.

Here's an example:
http://richnewman.wordpress.com/2007/04/15/a-beginner’s-guide-to-calling-a-net-library-from-excel/
 
Back
Top