Link to home
Start Free TrialLog in
Avatar of RIAS
RIASFlag for United Kingdom of Great Britain and Northern Ireland

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
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

could u pls post your code?
Avatar of RIAS

ASKER

oDoc.SaveAs(directoryName & "\CtsCreated\" & dtSQL.Rows(i)("Ref").ToString & dtSQL.Rows(i)("CorresType").ToString.First & " " & StrReportName & "_" & Date.Today.ToLongDateString & ".doc")
Try..

oDoc.SaveAs2(directoryName & "\CtsCreated\" & dtSQL.Rows(i)("Ref").ToString & dtSQL.Rows(i)("CorresType").ToString.First & " " & StrReportName & "_" & Date.Today.ToLongDateString & ".doc")

Open in new window

Avatar of Éric Moreau
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;
    }

Open in new window

Avatar of RIAS

ASKER

Pawan,
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")

Open in new window

Avatar of RIAS

ASKER

Hello Pawan,
This was the earlier one which didnt work:
oDoc.SaveAs(directoryName & "\CtsCreated\" & dtSQL.Rows(i)("Ref").ToString & dtSQL.Rows(i)("CorresType").ToString.First & " " & StrReportName & "_" & Date.Today.ToLongDateString & ".doc")
Try this ..  Every this it should create new file since we are passing date time.

oDoc.SaveAs(directoryName & "\CtsCreated\" & dtSQL.Rows(i)("Ref").ToString & dtSQL.Rows(i)("CorresType").ToString.First & " " & StrReportName & "_" & Now.ToString() & ".doc")

Open in new window


Changed - Now.ToString()
Avatar of RIAS

ASKER

Pawan,
Thanks but,it errors as invalid filepath .
Avatar of RIAS

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.
can you show the converted code?
Avatar of RIAS

ASKER

It could not convert it .
It gave the above error
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RIAS

ASKER

Will try and get back.Thanks a lot for your help.
Avatar of RIAS

ASKER

Eric,Worked like a charm!