Free Support Forum - aspose.com

Constructor form (string- string)

Is there a way to use a relative url in the file name string, rather than an absolute location on the hard drive?

For example, I’d rather use:

dim pdf as Form = new Form ("…/RootDirectory/pdf/source.pdf", “…/RootDirectory/pdf/destination.pdf”)

than:

dim pdf as Form = new Form (“c:\inetpub\wwwroot\RootDirectory\pdf\source.pdf”, “c:\inetpub\wwwroot\RootDirectory\pdf\destination.pdf”)

Thanks,
Greg

Dear gsheff,

Thanks for considering Aspose.

Yes, using the relative url is also ok.

Best regards.

I cannot make a relative path work successfully. When I use the following constructor:

dim pdf as Form = new Form ("/LocalDomain/source.pdf", “/LocalDomain/destination.pdf”)

I get the following error:
/LocalDomain/source.pdf not found as file or resource

I have tried various permutations on the relative path( eg ‘…/LocalDomain/source.pdf’, ‘/source.pdf’, etc.) with no success.

The absolute path (“c:\inetpub\LocalDomain\source.pdf”) works, as does the following command:
response.Redirect ("/LocalDomain/source.pdf")
so I know that the file exists and the relative path I am using is correct.

Any suggestions?
Greg

Dear Greg,

Is the /LocalDomain is the sub directory of your project path? If so,You just omit a dot before you path.

You can change it just like this:
response.Redirect ("./LocalDomain/source.pdf")

…/ means the parent path of your project.

Try it and if having any other problem please post it.

Best regards.

LocalDomain is the parent directory of the project.

Response.Redirect works as either:

Response.Redirect ("/LocalDomain/source.pdf")
or
Response.Redirect ("…/LocalDomain/source.pdf")
or
Response.Redirect (“source.pdf”)

The Aspose Form constructor works with none of these variations.

Any ideas?
Greg

Dear Greg,

I have tested it just now.

…\ is ok. It means jump to the up path of the curent project.
And all the / should changed to \ , then it is ok.

Best regards.

I still am having no success.

I was suprised to see you suggest that I should use a backslash in a relative path. I’m used to using forward slashes in relative paths and backslashes in absolute paths. I thought this might have been my problem, but had no luck after making the changes. I’ve tried multiple possible ways of pointing to the file. As I said before, all of these ways work fine for a non-aspose command (e.g. response.redirect), but when I cut and paste the relative path from response.redirect into the form constructor, I get a “not found as file or resource” error.

You mentioned that you have tested this succesfully. Can you post the exact constructor you used successfully?

Thanks,
Greg

Dear Greg,

Thank you for considering Aspose.

I have tested this issue and found the relative path can work in Windows app but can’t work in Web app. I suggest that you modify your code as the following:

string path = MapPath(".");
string file = path + (your relative file path);

This solves my problem. I was working on a web app.

Thank you,
Greg