Discussion:
Converting From VB.Net or C# to VBA
(too old to reply)
Neil
2012-08-24 16:28:36 UTC
Permalink
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
Peter Duniho
2012-08-24 17:57:07 UTC
Permalink
(follow-ups to m.p.dotnet.general)
Post by 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?
Frankly, the code isn't complex enough to warrant having run it through any
type of converter, and the VB.NET alternative is just a distraction in this
newsgroup. The code does nothing more than open a file via the managed
FileStream object, and then passes that object to the managed SharePoint
API (which is not part of the .NET API per se).

Your best approach would be to simply learn how the code works and
reimplement it from scratch in the VB environment.

The first prerequisite will be to find out whether the SharePoint library
you're trying to use even has a non-.NET (e.g. COM) library available for
use in VB. If it doesn't, there there will be no straight-forward way to
implement the .NET version of the code in VB.

If it does, then you simply need to find the analogous types in that API
for the ClientContext and File types, figure out what the
File.SaveBinaryDirect() equivalent in that other File type needs for input
(i.e. a byte array? a file name? a COM stream?), and then provide that
necessary input (creating it as needed).

None of the real questions have anything to do with .NET. You will find
the most appropriate audience for your question in a forum that is
specifically chartered for SharePoint questions. If you can find such a
forum that is further focused on unmanaged code and/or VB, so much the
better.

Pete
The Mad Ape
2012-08-24 18:25:34 UTC
Permalink
Post by 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
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);
}
}
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.
Arne Vajhøj
2012-08-25 00:59:49 UTC
Permalink
Post by The Mad Ape
Post by 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?
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
The Mad Ape
2012-08-25 09:51:46 UTC
Permalink
Post by Arne Vajhøj
Post by The Mad Ape
Post by 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?
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
I don't see too many helping him out. Do you? If you find it distasteful
you whiny bitch then help him out or fuck off.

TMA
Arne Vajhøj
2012-08-25 16:12:33 UTC
Permalink
Post by The Mad Ape
Post by Arne Vajhøj
Post by The Mad Ape
Post by 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?
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.
I don't see too many helping him out. Do you?
Yes.

He got two replies with two different approaches.
Post by The Mad Ape
If you find it distasteful
you whiny bitch then help him out or fuck off.
I did.

You did not.

So ...

Arne
Arne Vajhøj
2012-08-25 00:55:51 UTC
Permalink
Post by 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
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);
}
}
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
Neil
2012-08-25 16:06:14 UTC
Permalink
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
Post by 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
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);
}
}
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
Martin Crouch
2012-08-29 17:24:09 UTC
Permalink
Post by 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%E2%80%99s-guide-to-calling-a-net-library-from-excel/
Loading...