I have a file, it's on WebDAV server. I want to edit this file using neon WebDAV client library on C. What I want is - open this file in a default app for it's MIME type, and after I'll finish editing, it should save all changes on webdav server. My OS is Windows 7.
I have some questions.
- Should I download this file to temp directory first?
- Is there any neon command to do it?
- How can I know if file was changed?
- Is there any way to check if "save" button was clicked?
- When I'll make some changes in file, what command should I use to commit this changes to webdav server?
If someone has simple example, please, share it with me.
Update
Thank you again, and sorry for this "answer" issue. I've tried to use following code:
do {
fd = open("c:\\temp\\testdoc.docx", O_CREAT | O_RDWR, _S_IREAD | _S_IWRITE);
} while (fd == -1 && errno == EINTR);
if (fd == -1) {
const char *const errmsg = strerror(errno);
fprintf(stderr, "%s: %s.\n", "c:\\temp\\testdoc.docx", errmsg);
exit(1);
}
res =ne_get(sess, "/webdav/test/testdoc.docx", fd);
_close(fd);
But I'm still getting "We're sorry. We can't open testdoc.docx because we found a problem with it's contents" when i'm trying to open it with MS Word. Wern i'm downloading this file directly from my server, without using neon, this file has same size as file which was downloaded using ne_get command, and MS Office opens it perfectly.
Also, i've tried to create testdoc.docx using MS Word, and put it into my server, using following code:
do {
fd = open("c:\\temp\\testdoc.docx", O_CREAT | O_RDWR, _S_IREAD | _S_IWRITE);
} while (fd == -1 && errno == EINTR);
if (fd == -1) {
const char *const errmsg = strerror(errno);
fprintf(stderr, "%s: %s.\n", "c:\\temp\\testdoc.docx", errmsg);
exit(1);
}
res =ne_put(sess, "/webdav/test/testdoc.docx", fd);
_close(fd);
But res is 1 and error is: "Premature EOF in request body file".
Yes. You need to have the file stored in a physical local file. Otherwise you cannot open it in a local application.
For download, use the
ne_get
(from neon API).Use the
GetTempPath
WinAPI function to find out, where the current user's temporary directory is located.See the
FindFirstChangeNotification
WinAPI function.Alternatively check for a temporary file last modification timestamp in a loop, waiting for a change.
No. All you can do is to check if the file was changed.
Use the
ne_put
.Btw, is this an ultimate goal or just part of a larger application?
If this is an ultimate goal, there are tools that can do this out-of-the box. For example you can configure WinSCP (WebDAV client among other) to open a remote file on double-click in an associated application and have it upload the file back on save. In other words, WinSCP implements the exact solution I've outlined above. (I'm the author of WinSCP)