RIAS
asked on
Saveas need to save a copy
Hello,
I have a code which saves word document. but it just overwrites the already existing doc.What can I do to create a copy of document.
example :
xyz_1
Copy: xyz_1(1)
Cheers
I have a code which saves word document. but it just overwrites the already existing doc.What can I do to create a copy of document.
example :
xyz_1
Copy: xyz_1(1)
Cheers
could u pls post your code?
ASKER
oDoc.SaveAs(directoryName & "\CtsCreated\" & dtSQL.Rows(i)("Ref").ToStr ing & dtSQL.Rows(i)("CorresType" ).ToString .First & " " & StrReportName & "_" & Date.Today.ToLongDateStrin g & ".doc")
Try..
oDoc.SaveAs2(directoryName & "\CtsCreated\" & dtSQL.Rows(i)("Ref").ToString & dtSQL.Rows(i)("CorresType").ToString.First & " " & StrReportName & "_" & Date.Today.ToLongDateString & ".doc")
I have this C# code that should work;
public static string GetUniqueFilename(string fullPath)
{
if (!Path.IsPathRooted(fullPath))
fullPath = Path.GetFullPath(fullPath);
if (File.Exists(fullPath))
{
String filename = Path.GetFileName(fullPath);
String path = fullPath.Substring(0, fullPath.Length - filename.Length);
String filenameWOExt = Path.GetFileNameWithoutExtension(fullPath);
String ext = Path.GetExtension(fullPath);
int n = 1;
do
{
fullPath = Path.Combine(path, String.Format("{0} ({1}){2}", filenameWOExt, (n++), ext);
}
while (File.Exists(fullPath));
}
return fullPath;
}
ASKER
Pawan,
oDoc.SaveAs2 didn't do it.
oDoc.SaveAs2 didn't do it.
Try..
oDoc.SaveAs(directoryName & "\CtsCreated\" & dtSQL.Rows(i)("Ref").ToString & dtSQL.Rows(i)("CorresType").ToString.First & " " & StrReportName & "_" & Date.Today.ToLongDateString & ".doc")
ASKER
Hello Pawan,
This was the earlier one which didnt work:
oDoc.SaveAs(directoryName & "\CtsCreated\" & dtSQL.Rows(i)("Ref").ToStr ing & dtSQL.Rows(i)("CorresType" ).ToString .First & " " & StrReportName & "_" & Date.Today.ToLongDateStrin g & ".doc")
This was the earlier one which didnt work:
oDoc.SaveAs(directoryName & "\CtsCreated\" & dtSQL.Rows(i)("Ref").ToStr
Try this .. Every this it should create new file since we are passing date time.
Changed - Now.ToString()
oDoc.SaveAs(directoryName & "\CtsCreated\" & dtSQL.Rows(i)("Ref").ToString & dtSQL.Rows(i)("CorresType").ToString.First & " " & StrReportName & "_" & Now.ToString() & ".doc")
Changed - Now.ToString()
ASKER
Pawan,
Thanks but,it errors as invalid filepath .
Thanks but,it errors as invalid filepath .
ASKER
Eric,
I ried to convert your code to vb.net but got this error:
CONVERSION ERROR: Code could not be converted. Details:
-- line 1 col 17: invalid TypeDecl
Please check for any errors in the original code and try again.
I ried to convert your code to vb.net but got this error:
CONVERSION ERROR: Code could not be converted. Details:
-- line 1 col 17: invalid TypeDecl
Please check for any errors in the original code and try again.
can you show the converted code?
ASKER
It could not convert it .
It gave the above error
It gave the above error
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Will try and get back.Thanks a lot for your help.
ASKER
Eric,Worked like a charm!