How to convert office files (docx, xlsx) to google format in c# -
anyone share way convert docx, xlsx, pptx google format in programmatic. uploading through google drive api , sharing users using c#. every time creating duplicate document when edit file.
i want convert file while upload. can share converted file everyone.
i using google drive v3 api.
download code:
private static system.io.memorystream downloadfile(driveservice service, string fileid) { var request = service.files.get(fileid); var stream = new system.io.memorystream(); // add handler notified on progress changes. // notify on each chunk download , when // download completed or failed. request.mediadownloader.progresschanged += (google.apis.download.idownloadprogress progress) => { switch (progress.status) { case google.apis.download.downloadstatus.downloading: { console.writeline(progress.bytesdownloaded); break; } case google.apis.download.downloadstatus.completed: { console.writeline("download complete."); //savestream(stream, saveto); break; } case google.apis.download.downloadstatus.failed: { console.writeline("download failed."); break; } } }; request.download(stream); return stream; } private static void savestream(system.io.memorystream stream, string saveto) { using (system.io.filestream file = new system.io.filestream(saveto, system.io.filemode.create, system.io.fileaccess.write)) { stream.writeto(file); } }
here's started friend. check basic uploads , importing google docs types shows how upload , convert file types google formats.
var filemetadata = new file() { name = "my report", mimetype = "application/vnd.google-apps.spreadsheet" }; filesresource.createmediaupload request; using (var stream = new system.io.filestream("files/report.csv", system.io.filemode.open)) { request = driveservice.files.create( filemetadata, stream, "text/csv"); request.fields = "id"; request.upload(); } var file = request.responsebody; console.writeline("file id: " + file.id);
Comments
Post a Comment