Error Download - Unable to overwrite

I have an app on our web site that creates an excel file then downloads it. I’m now getting the error:

Unable to overwrite excel file: TrainingVideoReport.xls

Using this code:

WebFile.Open(MakeFile("xxx"), True)   <----------Same if False



Function MakeFile(FileName as String) as FolderItem

    'f=SpecialFolder.Temporary.Child(FileName + ".xls")   <-----------------This was the original line
    f=GetFolderItem(filename + ".xls") 
  
 ... Creates the file

   Return f
end

This did work at one point?

Any ideas.

It’s possible that the user running your app (usually Apache or www) doesn’t have permission to write into your app’s directory. Your commented code points to the temp dir.

@Greg O’Lone

In talking with the hosting company and the temporary directory is open for all to write to as you would expect. The current version writing to the apps directory, I set the permissions to 777 and still got the same error.

What should the next step in troubleshooting this be? Also the user running it is our company account not Apache or www.

Thanks, hope I can get this resolved soon.

@Greg O’Lone

What else can I trie, this is kind of urgent?

Thanks

Since the name of the actual file does not need to have a relationship with the file name of the WebFile, you could use

f=GetTemporaryFolderItem

That way you are certain there will be no collision.

You can even do

f=GetTemporaryFolderItem f.name = f.name + ".xls"

I will try that.

It worked!

I changed your code a little to

    f = GetTemporaryFolderItem
    f.name = filename + ".xls"

If you do not use the filename provided by the getTemporaryFolderItem, your present code is just the same as what you did before.

The parent of f is Temp.

If you change the name to a fixed filename, you will end up saving filename.xls in temp just the same.

The whole point of getTemporaryFolderItem is to have names that do not collide.

The thing about XLS files is that if Excel has the file open, you won’t be able to overwrite it.
Sometimes that can happen if the file has simply been clicked on in Explorer, and displayed as a preview.

@Michel Bujardet

I thought that might be the case, however it worked.

I’ll add the date and time stamp to the file name.

Why does it work though?

[quote=275715:@Richard Albrecht]@Michel Bujardet

I thought that might be the case, however it worked.

I’ll add the date and time stamp to the file name.

Why does it work though?[/quote]

It is possible that the system did some cleaning up in the meantime, as Linux regularly does. In Desktop Temporary is cleaned up at each reboot but on a server, I suspect a deamon will take care of that more often, since restarts can happen months apart.

That is the only explanation I can think of.