Exemplo n.º 1
0
        private async Task <long[]> getEmailLinkUri(string webUrl, string token)
        {
            List <long> recordUris = new List <long>();
            string      dbid       = "";
            var         mailResult = await ODataHelper.GetItem <MailItem>(GraphApiHelper.GetMailItemURL(webUrl), token, null);

            if (mailResult != null && mailResult.SingleValueExtendedProperties != null)
            {
                foreach (var prop in mailResult.SingleValueExtendedProperties)
                {
                    if (prop.Id.Equals(GraphApiHelper.IDPropName(), StringComparison.InvariantCultureIgnoreCase))
                    {
                        string[] idTokens = prop.Value.Split('/');

                        dbid = idTokens.First().Split(':').Last();

                        foreach (string s in prop.Value.Split(',', ';'))
                        {
                            long recordUri;
                            if (long.TryParse(s.Split('/').Last().Trim(), out recordUri))
                            {
                                if (!recordUris.Contains(recordUri))
                                {
                                    recordUris.Add(recordUri);
                                }
                            }
                        }
                    }

                    if (prop.Id.Equals(GraphApiHelper.IDPropNameForMAPIBIID(), StringComparison.InvariantCultureIgnoreCase))
                    {
                        dbid = prop.Value;
                    }

                    if (prop.Id.Equals(GraphApiHelper.IDPropNameForMAPIUri(), StringComparison.InvariantCultureIgnoreCase))
                    {
                        //long.TryParse(prop.Value.Split(',').First().Trim(), out recordUri);

                        foreach (string s in prop.Value.Split(','))
                        {
                            long recordUri;
                            if (long.TryParse(s.Trim(), out recordUri))
                            {
                                if (!recordUris.Contains(recordUri))
                                {
                                    recordUris.Add(recordUri);
                                }
                            }
                        }
                    }
                }

                if (dbid.EqualsIgnoreCase(this.Database.Id))
                {
                    return(recordUris.ToArray());
                }
            }

            return(new long[] { });
        }
Exemplo n.º 2
0
        public async Task <object> Post(DriveFileOperation request)
        {
            string token = await getToken();


            RegisterFileResponse response = new RegisterFileResponse();

            Record record = new Record(this.Database, request.Uri);

            string driveId = record.ExternalReference;

            var registeredFile = new RegisterdFileResponse()
            {
                Id = driveId
            };


            request.Action = request.Action ?? "";

            if (request.Action.IndexOf("AddToFavorites", StringComparison.InvariantCultureIgnoreCase) > -1)
            {
                record.AddToFavorites();
            }

            if (request.Action.IndexOf("RemoveFromFavorites", StringComparison.InvariantCultureIgnoreCase) > -1)
            {
                record.RemoveFromFavorites();
            }


            if (request.Action.IndexOf("checkin", StringComparison.InvariantCultureIgnoreCase) > -1)
            {
                var driveDetails = await ODataHelper.GetItem <string>(GraphApiHelper.GetOneDriveItemContentIdUrl(driveId), token);

                record.SetDocument(new InputDocument(driveDetails), true, false, "checkin from Word Online");
            }

            if (request.Action.IndexOf("delete", StringComparison.InvariantCultureIgnoreCase) > -1)
            {
                await ODataHelper.DeleteWithToken(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token);

                record.ExternalReference = "";
            }

            if (request.Action.IndexOf("finalize", StringComparison.InvariantCultureIgnoreCase) > -1)
            {
                record.SetAsFinal(false);
            }

            record.Save();

            updateFromRecord(registeredFile, record);

            response.Results = new List <RegisterdFileResponse>()
            {
                registeredFile
            };
            return(response);
        }
Exemplo n.º 3
0
        public async Task <object> Get(OpenFile request)
        {
            if (request.Uri < 1)
            {
                throw new Exception("Invalid Uri");
            }

            var response = new OpenFileResponse();
            var record   = new Record(this.Database, request.Uri);

            string token = await getToken();

            string driveId = record.ExternalReference;


            OneDriveItem fileResult = null;

            if (!string.IsNullOrWhiteSpace(driveId))
            {
                fileResult = await ODataHelper.GetItem <OneDriveItem>(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token, null);

                response.WebUrl = fileResult.WebUrl;
            }
            else if (record.IsElectronic)
            {
                string folderId = string.Empty;

                try
                {
                    var documentFolder = await ODataHelper.PostFolder <OneDriveItem>(GraphApiHelper.GetOneDriveChildrenUrl(), token);

                    folderId = documentFolder.Id;

                    if (!record.IsDocumentInClientCache)
                    {
                        record.LoadDocumentIntoClientCache();
                    }

                    var fileItem = await ODataHelper.PostFile <OneDriveItem>(GraphApiHelper.GetOneDriveFileUploadUrl(folderId, record.SuggestedFileName), token, record.DocumentPathInClientCache);

                    record.ExternalReference = fileItem.Id;
                    record.Save();
                    record.GetDocument(null, true, null, null);

                    response.WebUrl = fileItem.WebUrl;
                }
                catch
                {
                    throw;
                }
            }
            else
            {
                throw new Exception("Record is not a valid document.");
            }
            return(response);
        }
Exemplo n.º 4
0
        private async Task <Microsoft.Graph.DriveItem> doUpload(string filePath, string fileName, string accessToken)
        {
            string token = await getToken();

            var graphServiceClient = getClient(token);

            using (var file = System.IO.File.OpenRead(filePath))
            {
                MemoryStream stream = new MemoryStream();
                file.CopyTo(stream);


                autoOpen(stream);

                var documentFolder = await ODataHelper.PostFolder <OneDriveItem>(GraphApiHelper.GetOneDriveChildrenUrl(), token);


                var uploadSession = await graphServiceClient.Drives[documentFolder.ParentReference.DriveId].Items[documentFolder.Id].ItemWithPath(fileName).CreateUploadSession().Request().PostAsync();

                string ul = uploadSession.UploadUrl += "&$select=Id,ParentReference,WebUrl,WebDavUrl";

                var maxChunkSize = (320 * 1024) * 10;                 // 5000 KB - Change this to your chunk size. 5MB is the default.
                var provider     = new ChunkedUploadProvider(uploadSession, graphServiceClient, stream, maxChunkSize);


                // Setup the chunk request necessities
                var       chunkRequests     = provider.GetUploadChunkRequests();
                var       readBuffer        = new byte[maxChunkSize];
                var       trackedExceptions = new List <Exception>();
                DriveItem itemResult        = null;

                //upload the chunks
                foreach (var request in chunkRequests)
                {
                    // Do your updates here: update progress bar, etc.
                    // ...
                    // Send chunk request
                    var result = await provider.GetChunkRequestResponseAsync(request, readBuffer, trackedExceptions);

                    if (result.UploadSucceeded)
                    {
                        itemResult = result.ItemResponse;
                    }
                }

                // Check that upload succeeded
                if (itemResult != null)
                {
                    return(itemResult);
                }
            }
            throw new ApplicationException("Upload failed.");
        }
Exemplo n.º 5
0
        private async Task <string> getOneDriveDocumentUrl(string token)
        {
            long myUri = this.Database.CurrentUser.Uri;

            if (!_oneDriveDocuemntUrls.ContainsKey(myUri))
            {
                var driveDetails = await ODataHelper.GetItem <OneDriveDrive>(GraphApiHelper.GetMyOneDriveUrl(), token, null);

                _oneDriveDocuemntUrls.Add(myUri, driveDetails.WebUrl);
            }

            return(_oneDriveDocuemntUrls[myUri]);
        }
Exemplo n.º 6
0
        public async Task <object> Get(RegisterFile request)
        {
            var log = LogManager.GetLogger(typeof(RegisterFileService));

            log.Debug("GET start");
            RegisterFileResponse response = new RegisterFileResponse();



            log.Debug("getToken");
            string token = await getToken();

            log.Debug("gotToken");

            string driveId = getDriveIdFromTrim(request);

            log.Debug("got Drive ID");
            OneDriveItem fileResult = null;

            try
            {
                if (!string.IsNullOrWhiteSpace(request.WebUrl) && new string[] { "https://", "http://" }
                    .Any(s => request.WebUrl.StartsWith(s, StringComparison.InvariantCultureIgnoreCase)))
                {
                    log.Debug("GetItem");
                    var fullOneDriveItemsUrl = GraphApiHelper.GetOneDriveShareUrl(request.WebUrl);
                    fileResult = await ODataHelper.GetItem <OneDriveItem>(fullOneDriveItemsUrl, token, null);

                    log.Debug("GotItem");
                }
                else if (!string.IsNullOrWhiteSpace(driveId))
                {
                    fileResult = await ODataHelper.GetItem <OneDriveItem>(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token, null);
                }
            }
            catch
            {
                throw;
            }

            RegisterdFileResponse registeredFile = new RegisterdFileResponse();

            if (fileResult != null)
            {
                registeredFile.Id        = fileResult?.getDriveAndId();
                registeredFile.DriveItem = fileResult;

                TrimMainObjectSearch search = new TrimMainObjectSearch(this.Database, BaseObjectTypes.Record);
                TrimSearchClause     clause = new TrimSearchClause(this.Database, BaseObjectTypes.Record, SearchClauseIds.RecordSpURL);
                clause.SetCriteriaFromString(fileResult.getDriveAndId());

                search.AddSearchClause(clause);

                var uris = search.GetResultAsUriArray(2);

                if (uris.Count == 1)
                {
                    updateFromRecord(registeredFile, new Record(this.Database, uris[0]));
                }

                //if (request.Uri > 0)
                //{
                //	Record record = new Record(this.Database, request.Uri);
                //	response.RecordTitle = record.Title;
                //	response.Name = this.Database.CurrentUser.FormattedName;
                //}
            }

            response.Results = new List <RegisterdFileResponse>()
            {
                registeredFile
            };

            log.Debug("Finished");
            return(response);
        }
Exemplo n.º 7
0
        public async Task <object> Post(DriveFileOperation request)
        {
            try
            {
                RegisterFileResponse response = new RegisterFileResponse();

                Record record = new Record(this.Database, request.Uri);
                record.Refresh();

                string driveId = record.SpURL;

                var registeredFile = new RegisterdFileResponse()
                {
                    Id = driveId
                };


                request.Action = request.Action ?? "";

                if (request.Action.IndexOf("AddToFavorites", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    record.AddToFavorites();
                }

                if (request.Action.IndexOf("RemoveFromFavorites", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    record.RemoveFromFavorites();
                }


                if (request.Action.IndexOf("checkin", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    string token = await getToken();

                    if (!string.IsNullOrWhiteSpace(request.FileName))
                    {
                        //	filePath = Path.Combine(TrimApplication.WebServerWorkPath, record.SuggestedFileName);


                        //using (var stream = new FileStream(filePath, FileMode.Append))
                        //{
                        //	stream.Write(request.Data, 0, request.Data.Length);
                        //}

                        //if (request.LastDataSlice == true)
                        //{
                        //	record.SetDocument(new InputDocument(filePath), true, false, "checkin from Word Online");
                        //} else
                        //{
                        //	response.Results = new List<RegisterdFileResponse>() { registeredFile };
                        //	return response;
                        //}
                        //	var driveDetails = await ODataHelper.GetItem<string>(GraphApiHelper.GetOneDriveItemContentIdUrl(driveId), token, filePath);

                        var inputDocument = new InputDocument(request.FileName);


                        inputDocument.CheckinAs = request.WebUrl;
                        record.SetDocument(inputDocument, true, false, "checkin from Word Online");
                    }
                }

                if (request.Action.IndexOf("delete", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    string token = await getToken();

                    await ODataHelper.DeleteWithToken(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token);

                    record.SpURL = "";
                }

                if (request.Action.IndexOf("finalize", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    record.SetAsFinal(false);
                }

                record.Save();

                updateFromRecord(registeredFile, record);

                response.Results = new List <RegisterdFileResponse>()
                {
                    registeredFile
                };
                return(response);
            }
            finally
            {
                if (!string.IsNullOrWhiteSpace(request.FileName))
                {
                    File.Delete(request.FileName);
                }
            }
        }
Exemplo n.º 8
0
        public async Task <object> Get(RegisterFile request)
        {
            var log = LogManager.GetLogger(typeof(RegisterFileService));

            log.Debug("GET start");
            RegisterFileResponse response = new RegisterFileResponse();



            log.Debug("getToken");
            string token = await getToken();

            log.Debug("gotToken");

            string driveId = getDriveIdFromTrim(request);

            log.Debug("got Drive ID");
            OneDriveItem fileResult = null;

            long recordUri = 0;

            RegisterdFileResponse registeredFile = new RegisterdFileResponse();

            try
            {
                if (request.IsEmail)
                {
                    recordUri = await getEmailLinkUri(request.WebUrl, token);

                    //var mailResult = await ODataHelper.GetItem<MailItem>(GraphApiHelper.GetMailItemURL(request.WebUrl), token, null);

                    //if (mailResult != null && mailResult.SingleValueExtendedProperties != null)
                    //{
                    //	foreach (var prop in mailResult.SingleValueExtendedProperties)
                    //	{
                    //		if (prop.Id.Equals(GraphApiHelper.IDPropName(), StringComparison.InvariantCultureIgnoreCase))
                    //		{
                    //			long.TryParse(prop.Value.Split('/').Last(), out recordUri);
                    //		}
                    //	}
                    //}
                }

                if (request.IsEmail && recordUri == 0)
                {
                    var emailUrl = GraphApiHelper.GetEMLUrl(request.WebUrl);

                    string userFolder = Path.Combine("ForUser", this.Database.CurrentUser.Uri.ToString());

                    string fullUserFolder = Path.Combine(this.ServiceDefaults.UploadBasePath, userFolder);

                    Directory.CreateDirectory(fullUserFolder);
                    string fileName = Path.ChangeExtension(request.WebUrl, "eml");
                    string filePath = Path.Combine(fullUserFolder, fileName);


                    await ODataHelper.GetItem <string>(emailUrl, token, filePath);

                    registeredFile.EmailPath = Path.Combine(userFolder, fileName);;
                }
                else if (!string.IsNullOrWhiteSpace(request.WebUrl) && new string[] { "https://", "http://" }
                         .Any(s => request.WebUrl.StartsWith(s, StringComparison.InvariantCultureIgnoreCase)))
                {
                    log.Debug("GetItem");
                    var fullOneDriveItemsUrl = GraphApiHelper.GetOneDriveShareUrl(request.WebUrl);
                    fileResult = await ODataHelper.GetItem <OneDriveItem>(fullOneDriveItemsUrl, token, null);

                    log.Debug("GotItem");
                }
                else if (!string.IsNullOrWhiteSpace(driveId) && !request.IsEmail)
                {
                    fileResult = await ODataHelper.GetItem <OneDriveItem>(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token, null);
                }
            }
            catch
            {
                throw;
            }



            DroppedFilesUserOptions fileOptions = new DroppedFilesUserOptions(this.Database);
            var options = new TrimOptions();

            if (fileOptions.UseDefaultRecordTypeInOffice == true)
            {
                options.DefaultDocumentRecordType = fileOptions.RecordType.Uri;
            }

            registeredFile.Options = options;

            var enumItems = new List <MyEnumItem>();

            HP.HPTRIM.SDK.Enum relationshipEnum = new HP.HPTRIM.SDK.Enum(AllEnumerations.RecordRelationshipType, this.Database);

            foreach (var relEnum in relationshipEnum.GetItemArray(new int[] { (int)RecordRelationshipType.InSharepointSite, (int)RecordRelationshipType.IsInSeries, (int)RecordRelationshipType.IsRootPart, (int)RecordRelationshipType.IsTempCopy, (int)RecordRelationshipType.IsVersion, (int)RecordRelationshipType.RedactionOf }, true).OrderBy(ei => ei.Caption))
            {
                enumItems.Add(new MyEnumItem()
                {
                    Name = relEnum.Name, Caption = relEnum.Caption
                });
            }

            Dictionary <string, IList <MyEnumItem> > enumDetails = new Dictionary <string, IList <MyEnumItem> >();

            enumDetails.Add("RecordRelationshipType", enumItems);

            registeredFile.Enums = enumDetails;

            if (fileResult != null)
            {
                registeredFile.Id        = fileResult?.getDriveAndId();
                registeredFile.DriveItem = fileResult;

                TrimMainObjectSearch search = new TrimMainObjectSearch(this.Database, BaseObjectTypes.Record);

                search.AddSearchClause(fileResult.getDriveAndId().GetDriveIdSearchClause(this.Database));

                var uris = search.GetResultAsUriArray(2);

                if (uris.Count == 1)
                {
                    updateFromRecord(registeredFile, new Record(this.Database, uris[0]));
                }
            }
            else if (request.IsEmail && recordUri > 0)
            {
                updateFromRecord(registeredFile, new Record(this.Database, recordUri));
            }

            response.Results = new List <RegisterdFileResponse>()
            {
                registeredFile
            };

            log.Debug("Finished");
            return(response);
        }
Exemplo n.º 9
0
        public async Task <object> Post(DriveFileOperation request)
        {
            string fileName = request.FileName;

            try
            {
                RegisterFileResponse response = new RegisterFileResponse();

                Record record = new Record(this.Database, request.Uri);
                record.Refresh();

                string driveId = record.GetDriveId();

                var registeredFile = new RegisterdFileResponse()
                {
                    Id = driveId
                };


                request.Action = request.Action ?? "";

                if (request.Action.IndexOf("AddToFavorites", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    record.AddToFavorites();
                }

                if (request.Action.IndexOf("RemoveFromFavorites", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    record.RemoveFromFavorites();
                }

                if (request.Action.IndexOf("checkin", StringComparison.InvariantCultureIgnoreCase) > -1 &&
                    request.Action.IndexOf("checkin-requst-del", StringComparison.InvariantCultureIgnoreCase) < 1)
                {
                    string token = await getToken();

                    if (!string.IsNullOrWhiteSpace(request.FileName))
                    {
                        if (!Path.IsPathRooted(request.FileName))
                        {
                            fileName = Path.Combine(this.ServiceDefaults.UploadBasePath, request.FileName);
                        }

                        var inputDocument = new InputDocument(fileName);

                        inputDocument.CheckinAs = request.WebUrl;
                        record.SetDocument(inputDocument, true, false, "checkin from Word Online");
                    }
                    else
                    {
                        string downloadUrl = GraphApiHelper.GetOneDriveItemContentIdUrl(driveId);

                        var fileResult = await ODataHelper.GetItem <OneDriveItem>(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token, null);

                        string filePath = Path.Combine(TrimApplication.WebServerWorkPath, fileResult.Name);


                        await ODataHelper.GetItem <string>(downloadUrl, token, filePath);



                        var inputDocument = new InputDocument(filePath);


                        inputDocument.CheckinAs = record.SuggestedFileName;
                        record.SetDocument(inputDocument, true, false, "checkin from Word Online");
                    }
                }

                if (request.Action.IndexOf("request-del", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    record.SetDeleteNow(!record.GetDeleteNow());
                }

                if (request.Action.IndexOf("delete", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    string token = await getToken();

                    await ODataHelper.DeleteWithToken(GraphApiHelper.GetOneDriveItemIdUrlForDelete(driveId), token);

                    record.SetDriveId("");
                }

                if (request.Action.IndexOf("finalize", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    record.SetAsFinal(false);
                }

                record.Save();

                updateFromRecord(registeredFile, record);

                response.Results = new List <RegisterdFileResponse>()
                {
                    registeredFile
                };
                return(response);
            }
            finally
            {
                if (!string.IsNullOrWhiteSpace(fileName))
                {
                    File.Delete(fileName);
                }
            }
        }
Exemplo n.º 10
0
        public async Task <object> Get(RegisterFile request)
        {
            RegisterFileResponse response = new RegisterFileResponse();

            //string[] addinScopes = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/scope").Value.Split(' ');

            string token = await getToken();


            string driveId = getDriveIdFromTrim(request);

            OneDriveItem fileResult = null;

            try
            {
                if (!string.IsNullOrWhiteSpace(request.WebUrl))
                {
                    var driveDetails = await ODataHelper.GetItem <OneDriveDrive>(GraphApiHelper.GetMyOneDriveUrl(), token);

                    string filePath = request.WebUrl.Substring(driveDetails.WebUrl.Length);

                    var fullOneDriveItemsUrl = GraphApiHelper.GetOneDriveItemPathsUrl(filePath);
                    fileResult = await ODataHelper.GetItem <OneDriveItem>(fullOneDriveItemsUrl, token);
                }
                else if (!string.IsNullOrWhiteSpace(driveId))
                {
                    fileResult = await ODataHelper.GetItem <OneDriveItem>(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token);
                }
            }
            catch
            {
                throw;
            }


            var registeredFile = new RegisterdFileResponse()
            {
                Id = fileResult?.Id, DriveItem = fileResult
            };


            TrimMainObjectSearch search = new TrimMainObjectSearch(this.Database, BaseObjectTypes.Record);
            TrimSearchClause     clause = new TrimSearchClause(this.Database, BaseObjectTypes.Record, SearchClauseIds.RecordExternal);

            clause.SetCriteriaFromString(fileResult.Id);

            search.AddSearchClause(clause);

            var uris = search.GetResultAsUriArray(2);

            if (uris.Count == 1)
            {
                updateFromRecord(registeredFile, new Record(this.Database, uris[0]));
            }
            //if (request.Uri > 0)
            //{
            //	Record record = new Record(this.Database, request.Uri);
            //	response.RecordTitle = record.Title;
            //	response.Name = this.Database.CurrentUser.FormattedName;
            //}



            response.Results = new List <RegisterdFileResponse>()
            {
                registeredFile
            };
            return(response);
        }
Exemplo n.º 11
0
        public async Task <object> Get(OpenFile request)
        {
            if (request.Uri < 1)
            {
                throw new HttpError(HttpStatusCode.BadRequest, "400", "Invalid Uri");
            }

            var response = new OpenFileResponse()
            {
                UserHasAccess = true
            };
            var record = new Record(this.Database, request.Uri);

            string driveId = record.SpURL;

            if (!string.IsNullOrWhiteSpace(driveId))
            {
                OneDriveItem fileResult = null;
                string       token      = await getToken();

                try
                {
                    fileResult = await ODataHelper.GetItem <OneDriveItem>(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token, null);
                }
                catch (Exception ex)
                {
                    response.UserHasAccess = false;
                }

                if (response.UserHasAccess == false)
                {
                    token      = getApplicationToken();
                    fileResult = await ODataHelper.GetItem <OneDriveItem>(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token, null);
                }
                response.WebUrl    = fileResult.WebUrl;
                response.WebDavUrl = fileResult.WebDavUrl;
            }
            else if (record.IsElectronic)
            {
                try
                {
                    string token = await getToken();

                    string folderId = string.Empty;

                    var documentFolder = await ODataHelper.PostFolder <OneDriveItem>(GraphApiHelper.GetOneDriveChildrenUrl(), token);

                    folderId = documentFolder.Id;

                    if (!record.IsDocumentInClientCache)
                    {
                        record.LoadDocumentIntoClientCache();
                    }

                    Regex pattern = new Regex("[\\\\/<>|?]|[\n]{2}");

                    string fileName = $"{Path.GetFileNameWithoutExtension(record.SuggestedFileName)} ({pattern.Replace(record.Number, "_")}){Path.GetExtension(record.SuggestedFileName)}";



                    var uploadedFile = await doUpload(record.DocumentPathInClientCache, fileName, token);

                    record.GetDocument(null, true, null, uploadedFile.ParentReference.DriveId + "/items/" + uploadedFile.Id);
                    record.SpURL = uploadedFile.ParentReference.DriveId + "/items/" + uploadedFile.Id;                    // uploadedFile. fileItem.getDriveAndId();

                    record.Save();


                    response.WebUrl    = uploadedFile.WebUrl;
                    response.WebDavUrl = uploadedFile.WebDavUrl;
                }
                catch
                {
                    try
                    {
                        record.UndoCheckout(null);
                    }
                    catch { }
                    //	return new Error
                    throw;
                }
            }
            else
            {
                throw new Exception("Record is not a valid document.");
            }
            return(response);
        }