Ich versuche grad ganz dringend folgenden Artikel :
http://support.microsoft.com/kb/830561/DE/#3(Punkt 3)
nach C# umzubauen.
Orginal VB
Sub Test()
Dim strFilePath As String
Dim strPath As String
Dim intCounter As Integer
Dim strFileName As String
Dim OldServer As String
Dim NewServer As String
Dim objDoc As Document
Dim objTemplate As Template
Dim dlgTemplate As Dialog
OldServer = "<\\rsnj01\vol1>"
NewServer = "<\\rsnyc1p\vol3>"
strFilePath = InputBox("What is the folder location that you want to use?")
If Right(strFilePath, 1) <> "\" Then strFilePath = strFilePath & "\"
strFileName = Dir(strFilePath & "*.doc")
Do While strFileName <> ""
objDoc = Documents.Open(strFilePath & strFileName)
objTemplate = objDoc.AttachedTemplate
dlgTemplate = Dialogs(wdDialogToolsTemplates)
strPath = dlgTemplate.Template
If LCase(Left(strPath, 13)) = LCase(OldServer) Then
objDoc.AttachedTemplate = NewServer & Mid(strPath, 14)
End If
strFileName = Dir()
objDoc.Save()
objDoc.Close()
Loop
objDoc = Nothing
objTemplate = Nothing
dlgTemplate = Nothing
End Sub
Das C# Programm:
void Test() {
string strFilePath;
string strPath;
int intCounter;
string strFileName;
string OldServer;
string NewServer;
Document objDoc;
Template objTemplate;
Dialog dlgTemplate;
OldServer = "<\\\\rsnj01\\vol1>";
NewServer = "<\\\\rsnyc1p\\vol3>";
strFilePath = InputBox("What is the folder location that you want to use?");
if ((strFilePath.Substring((strFilePath.Length - 1)) != "\\")) {
strFilePath = (strFilePath + "\\");
}
strFileName = Dir((strFilePath + "*.doc"));
while ((strFileName != "")) {
objDoc = Documents.Open((strFilePath + strFileName));
objTemplate = objDoc.AttachedTemplate;
dlgTemplate = Dialogs(wdDialogToolsTemplates);
strPath = dlgTemplate.Template;
if ((strPath.Substring(0, 13).ToLower() == OldServer.ToLower())) {
objDoc.AttachedTemplate = (NewServer + strPath.Substring(13));
}
strFileName = Dir();
objDoc.Save();
objDoc.Close();
}
objDoc = null;
objTemplate = null;
dlgTemplate = null;
}
Leider hab ich mal so keine ahnung von VB. Und stoße bei Folgendem auf Problemen:
Die Objekte :
Document ,Template, Dialog
(wobei letzteres net so das Problem sein dürfte)
werden nicht erkannt. Ich hab dannach gegooglet ob evtl. ein verweis fehlt aber naja das ist bei solchen Namen wie die Nadel im Heuhaufen.
Dann erkennt er "Dir" nicht. Aber das ist glaubich ne VB sache. Gibt es dazu nen C# Äquivalent?(vielleicht Directory?)
Naja das wars auch eigendlich. Ich brauche das Script halt dringend am laufen kann mir bitte bitte wer helfen ?
Danke schonmal im vorraus
Christopher