What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 11337 |  Welcome, Guest!   Register  Login
 Home > Forums > DotNetFunda.Com > How to convert this VB code into C#? ...
Gudevg

How to convert this VB code into C#?

Replies: 1 | Posted by: Gudevg on 5/3/2012 | Category: DotNetFunda.Com Forums | Views: 599 | Status: [Member] | Points: 10  


Hi everyone,
I develop the below code to fetch figures from word document and convert it into Image format. I develop this in VB, I tried to convert it into C#.

First of all i tried to convert it into VB.Net using Upgrade VB using Visual Studio but it shows some errors and it is not convert it into VB.net format Please anyone look into this code and help me in this regards,


Sub ImageToIncludePicture()
Dim oShp As InlineShape

If ActiveDocument.InlineShapes.Count <> 0 Then
Dim oFSO As New Scripting.FileSystemObject

If oFSO.FolderExists("c:\temp\epub") = False Then
If oFSO.FolderExists("c:\temp") = False Then
oFSO.CreateFolder ("c:\temp")
End If
oFSO.CreateFolder ("c:\temp\epub")
End If

Dim strImgPath As String
strImgPath = ActiveDocument.Path & "\images\"
If oFSO.FolderExists(strImgPath) = False Then
oFSO.CreateFolder (strImgPath)
End If

Dim oTmp As Template
Dim sPath As String

Dim sToolPath As String
sToolPath = "D:\00_Projects\ePub\Templates\text2img.exe"

img = 1
For Each oShp In ActiveDocument.InlineShapes
oShp.Select
If Selection.Fields.Count = 0 Then
If Selection.Paragraphs(1).Range.Text <> "" Then
Selection.Paragraphs.Style = "Normal"
End If
Dim strImg As String
Dim strExt As String
strImg = oShp.Range.XML
Dim oReg As New VBScript_RegExp_55.RegExp
Dim oMat As Match
Dim oMatC As MatchCollection
strImg = Replace(strImg, ChrW(13), "<br/>")
strImg = Replace(strImg, ChrW(10), "<br/>")
oReg.Pattern = "<w:binData w:name=""wordml://(.*?)"">(.*?)</w:binData>"
oReg.Global = True
oReg.IgnoreCase = True
oReg.Multiline = True
If oReg.test(strImg) = True Then
Set oMatC = oReg.Execute(strImg)
Set oMat = oMatC.Item(0)
Dim strTest As String
strTest = oMat.SubMatches(1)
strTest = Replace(oMat.SubMatches(1), "<br/><br/>", vbLf)

Open "c:\temp\ePub\input.txt" For Output As #1
Print #1, strTest
Close #1
strExt = oMat.SubMatches(0)
Selection.Delete
strExt = Right(strExt, 4)
Shell sToolPath & " ""c:\temp\epub\input.txt"" """ & strImgPath & "\image" & Format(img, "00") & strExt & """", vbHide
While (oFSO.FileExists(strImgPath & "\image" & Format(img, "00") & strExt) = False)

Wend
Selection.Fields.Add Selection.Range, wdFieldIncludePicture, """images/image" & Format(img, "00") & strExt & """"
img = img + 1
End If
End If
Next
End If
End Sub


Thanks in advance.
Deepak G.

Deepakkumar G.


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

Oswaldlily
Oswaldlily  
Posted on: 5/3/2012 2:22:37 AM
Level: Starter | Status: [Member] | Points: 50

Resolved

void ImageToIncludePicture() {
InlineShape oShp;
if ((ActiveDocument.InlineShapes.Count != 0)) {
Scripting.FileSystemObject oFSO = new Scripting.FileSystemObject();
if ((oFSO.FolderExists("c:\\temp\\epub") == false)) {
if ((oFSO.FolderExists("c:\\temp") == false)) {
oFSO.CreateFolder("c:\\temp");
}
oFSO.CreateFolder("c:\\temp\\epub");
}
string strImgPath;
strImgPath = (ActiveDocument.Path + "\\images\\");
if ((oFSO.FolderExists(strImgPath) == false)) {
oFSO.CreateFolder(strImgPath);
}
Template oTmp;
string sPath;
string sToolPath;
sToolPath = "D:\\00_Projects\\ePub\\Templates\\text2img.exe";
img = 1;
foreach (oShp in ActiveDocument.InlineShapes) {
oShp.Select;
if ((Selection.Fields.Count == 0)) {
if ((Selection.Paragraphs(1).Range.Text != "")) {
Selection.Paragraphs.Style = "Normal";
}
string strImg;
string strExt;
strImg = oShp.Range.XML;
VBScript_RegExp_55.RegExp oReg = new VBScript_RegExp_55.RegExp();
Match oMat;
MatchCollection oMatC;
strImg = strImg.Replace('\r', "<br/>");
strImg = strImg.Replace('\n', "<br/>");
oReg.Pattern = "<w:binData w:name=\"wordml://(.*?)\">(.*?)</w:binData>";
oReg.Global = true;
oReg.IgnoreCase = true;
oReg.Multiline = true;
if ((oReg.test(strImg) == true)) {
oMatC = oReg.Execute(strImg);
oMat = oMatC.Item[0];
string strTest;
strTest = oMat.SubMatches(1);
strTest = oMat.SubMatches(1).Replace("<br/><br/>", "\n");
Open;
"c:\\temp\\ePub\\input.txt";
for (object Output; ; Output++) {
// TODO: # ... Warning!!! not translated
1;
Print;
// TODO: # ... Warning!!! not translated
1;
strTest;
Close;
// TODO: # ... Warning!!! not translated
1;
strExt = oMat.SubMatches(0);
Selection.Delete;
strExt = strExt.Substring((strExt.Length - 4));
Shell;
(sToolPath + (" \"c:\\temp\\epub\\input.txt\" \""
+ (strImgPath + ("\\image"
+ (Format(img, "00")
+ (strExt + "\""))))));
vbHide;
while ((oFSO.FileExists((strImgPath + ("\\image"
+ (Format(img, "00") + strExt)))) == false)) {
Selection.Fields.Add;
Selection.Range;
wdFieldIncludePicture;
("\"images/image"
+ (Format(img, "00")
+ (strExt + "\"")));
img = (img + 1);
}
}
}
}
}
}
}

Gudevg, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Reply - Please login to reply


Click here to login & reply

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/21/2013 4:44:37 PM