Skip to main content

Google Drive API: Copy & Moving files between folders

Cloud Storage Access through API - ASP.NET MVC 5 - C# (Part-4) 

Google Drive API v3 - a) Move files between folders, 
                                      b) Copy files between folders.     

                                2) Google Drive API - File Upload, View, Download & Delete 
                                   3) Google Drive API - Create folder, Upload file to folder, Show folder Contain. 
                                   4) Google Drive API - Move & Copy files between folders.
                                   5) Google Drive API - Manage Share & Set User Role Permissions.
                                   6) Google Drive API - View Share Users Permission Details.

Source Code:  Click to download [11.1 MB]

This tutorial is a continuation in Part-1, Part-2 & Part-3:
In Part-3 of this video series, we have seen "Create Folder, Upload file to folder, Show folders contain in Google Drive using Google Drive API v3 ". 


If you want to Move or Copy a file to another folder within google drive then you need to provide a file ID & Folder ID.

1: Here file ID is the file that you want to move or copy.
2: Folder ID means a folder as a destination, where you want to move or copy the file. 
3: After that, we need know to there parent ids & switching the parents of the file (for file move) or adding another existing parent to file (for file copy).

Programmatically, what are the typical step you need to do?
Step-1: Populate Dropdown with folders Name & ids.  
Step-2: Dynamically Move files between folders. 
Step-3: Dynamically Copy files between folders. 
           

Step-1: Populate Dropdown with folders Name & ids.  


a) First, we need to create the Google Drive API Services & request a ListRequest of files.
b) After a query that filters the ListRequest request with mimeType. Here I am using 'application/vnd.google-apps.folder' type' that means all folders of google drive. 
c) only folder ids & names are retrieved from In ListRequest result object & stored into the FolderList collection & Finally this FolderList is populated within a dropdown List (As you can see this above picture).

Please see this code: 
public static List<GoogleDriveFiles> GetDriveFolders()
        {
            Google.Apis.Drive.v3.DriveService service = GetService_v3();
            List<GoogleDriveFiles> FolderList = new List<GoogleDriveFiles>();

            Google.Apis.Drive.v3.FilesResource.ListRequest request = service.Files.List();
            request.Q = "mimeType='application/vnd.google-apps.folder'";
            request.Fields = "files(id, name)";

            Google.Apis.Drive.v3.Data.FileList result = request.Execute();
            foreach (var file in result.Files)
            {
                GoogleDriveFiles File = new GoogleDriveFiles
                {
                    Id = file.Id,
                    Name = file.Name,
                    Size = file.Size,
                    Version = file.Version,
                    CreatedTime = file.CreatedTime
                };
                FolderList.Add(File);
            }
            return FolderList;
        }
Step-2: Dynamically Move files between folders? 

Programmatically,
a) We need to retrieve the parents ID of existing file by using GetRequest class object.
b) Create an update request for existing file ID by using UpdateRequest class object. 
c) To Add new parents by using AddParents property of UpdateRequest class.
d) To Remove previous parents by using RemoveParents property of UpdateRequest class. 

Please see this code: 
public static string MoveFiles(String fileId, String folderId)
        {
            Google.Apis.Drive.v3.DriveService service = GetService_v3();

            // Retrieve the existing parents to remove
            Google.Apis.Drive.v3.FilesResource.GetRequest getRequest = service.Files.Get(fileId);
            getRequest.Fields = "parents";
            Google.Apis.Drive.v3.Data.File file = getRequest.Execute();
            string previousParents = String.Join(",", file.Parents);
            
            // Move the file to the new folder
            Google.Apis.Drive.v3.FilesResource.UpdateRequest updateRequest = service.Files.Update(new Google.Apis.Drive.v3.Data.File(), fileId);
            updateRequest.Fields = "id, parents";
            updateRequest.AddParents = folderId;
            updateRequest.RemoveParents = previousParents;
            
            file = updateRequest.Execute();
            if (file != null) {
                return "Success";
            }
            else {
                return "Fail";
            }
}

Step-3: Dynamically Copy files between folders.

Programmatically,
A) We need to retrieve the parents ID of existing file by using GetRequest class object.
B) Create an update request for existing file ID by using UpdateRequest class object. 
A) To Add new parents by using AddParents property of UpdateRequest class. 

Please see this code: 
public static string CopyFiles(String fileId, String folderId)
        {
            Google.Apis.Drive.v3.DriveService service = GetService_v3();

            // Retrieve the existing parents to remove
            Google.Apis.Drive.v3.FilesResource.GetRequest getRequest = service.Files.Get(fileId);
            getRequest.Fields = "parents";
            Google.Apis.Drive.v3.Data.File file = getRequest.Execute();

            // Copy the file to the new folder
            Google.Apis.Drive.v3.FilesResource.UpdateRequest updateRequest = service.Files.Update(new Google.Apis.Drive.v3.Data.File(), fileId);
            updateRequest.Fields = "id, parents";
            updateRequest.AddParents = folderId;
            //updateRequest.RemoveParents = previousParents;
            file = updateRequest.Execute();
            if (file != null)
            {
                return "Success";
            }
            else
            {
                return "Fail";
            }
}

Let's do it using Visual Studio MVC Application

First, Goto the Visual Studio 2013 or Higher Version.

Step 1: Create an Empty MVC Project. Name of the project: GoogleDriveRestAPI.
Step 2: Opening the NuGet Package Manager Console, Select the package source and run this following two command. 

PM> Install-Package Google.Apis.Drive.v2
PM> Install-Package Google.Apis.Drive.v3

Here I am using Google Drive API v2 & v3, 

Step 3 (Model): 
First, we need to create two model class under the Model folder of project solution. 
Model Class 1: GoogleDriveFiles.cs & 
Model Class 2: DDLOptions.cs

Please Copy & Paste this code into this class.

Model Class 1: GoogleDriveFiles.cs :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace GoogleDriveRestAPI_v3.Models
{
    public class GoogleDriveFiles
    {
          public string Id { get; set; }
          public string Name { get; set; }
          public long? Size { get; set; }
          public long? Version { get; set; }
          public DateTime? CreatedTime { get; set; }
          public IList<string> Parents { get; set; }
    }
}

Model Class 2: DDLOptions.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace GoogleDriveRestAPI_v3.Models
{
    public class DDLOptions
    {
        public string Id { get; set; }
        public string Name { get; set; }
    }
}

Step 4 (Repository): 
After that, create another class (Name: GoogleDriveFilesRepository.csunder this same Model folder. Please Copy & Paste this below code.

using Google.Apis.Auth.OAuth2;
using Google.Apis.Drive.v2;
using Google.Apis.Drive.v2.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
using System.Web;
using Google.Apis.Download;
using Google.Apis.Requests;

namespace GoogleDriveRestAPI_v3.Models
{
    public class GoogleDriveFilesRepository
    {
        public static string[] Scopes = { Google.Apis.Drive.v3.DriveService.Scope.Drive };
        public static Google.Apis.Drive.v3.DriveService GetService_v3()
        {
            UserCredential credential;
            using (var stream = new FileStream(@"D:\client_secret.json", FileMode.Open, FileAccess.Read))
            {
                String FolderPath = @"D:\";
                String FilePath = Path.Combine(FolderPath, "DriveServiceCredentials.json");

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(FilePath, true)).Result;
            }

            //Create Drive API service.
            Google.Apis.Drive.v3.DriveService service = new Google.Apis.Drive.v3.DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = "GoogleDriveRestAPI-v3",
            });

            return service;
        }
        public static Google.Apis.Drive.v2.DriveService GetService_v2()
        {
            UserCredential credential;
            using (var stream = new FileStream(@"D:\client_secret.json", FileMode.Open, FileAccess.Read))
            {
                String FolderPath = @"D:\";
                String FilePath = Path.Combine(FolderPath, "DriveServiceCredentials.json");

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(FilePath, true)).Result;
            }

            //Create Drive API service.
            Google.Apis.Drive.v2.DriveService service = new Google.Apis.Drive.v2.DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = "GoogleDriveRestAPI-v2",
            });

            return service;
        }
        public static List<GoogleDriveFiles> GetContainsInFolder(String folderId)
        {
            List<string> ChildList = new List<string>();
            Google.Apis.Drive.v2.DriveService ServiceV2 = GetService_v2();
            ChildrenResource.ListRequest ChildrenIDsRequest = ServiceV2.Children.List(folderId);
            do
            {
                ChildList children = ChildrenIDsRequest.Execute();

                if (children.Items != null && children.Items.Count > 0)
                {
                    foreach (var file in children.Items)
                    {
                        ChildList.Add(file.Id);
                    }
                }
                ChildrenIDsRequest.PageToken = children.NextPageToken;

            } while (!String.IsNullOrEmpty(ChildrenIDsRequest.PageToken));

            //Get All File List
            List<GoogleDriveFiles> AllFileList = GetDriveFiles();
            List<GoogleDriveFiles> Filter_FileList = new List<GoogleDriveFiles>();

            foreach (string Id in ChildList)
            {
                Filter_FileList.Add(AllFileList.Where(x => x.Id == Id).FirstOrDefault());
            }
            return Filter_FileList;
        }
        public static void CreateFolder(string FolderName)
        {
            Google.Apis.Drive.v3.DriveService service = GetService_v3();

            Google.Apis.Drive.v3.Data.File FileMetaData = new Google.Apis.Drive.v3.Data.File();
            FileMetaData.Name = FolderName;
            FileMetaData.MimeType = "application/vnd.google-apps.folder";

            Google.Apis.Drive.v3.FilesResource.CreateRequest request;

            request = service.Files.Create(FileMetaData);
            request.Fields = "id";
            var file = request.Execute();
            //Console.WriteLine("Folder ID: " + file.Id);
        }
        public static List<GoogleDriveFiles> GetDriveFiles()
        {
            Google.Apis.Drive.v3.DriveService service = GetService_v3();

            // Define parameters of request.
            Google.Apis.Drive.v3.FilesResource.ListRequest FileListRequest = service.Files.List();
            FileListRequest.Fields = "nextPageToken, files(createdTime, id, name, size, version, trashed, parents, webViewLink)";

            // List files.
            IList<Google.Apis.Drive.v3.Data.File> files = FileListRequest.Execute().Files;
            List<GoogleDriveFiles> FileList = new List<GoogleDriveFiles>();

            if (files != null && files.Count > 0)
            {
                foreach (var file in files)
                {
                    GoogleDriveFiles File = new GoogleDriveFiles
                    {
                        Id = file.Id,
                        Name = file.Name,
                        Size = file.Size,
                        Version = file.Version,
                        CreatedTime = file.CreatedTime,
                        Parents = file.Parents,
                        webViewLink = file.WebViewLink
                    };
                    FileList.Add(File);
                }
            }
            return FileList;
        }
        public static void FileUpload(HttpPostedFileBase file)
        {
            if (file != null && file.ContentLength > 0)
            {
                Google.Apis.Drive.v3.DriveService service = GetService_v3();

                string path = Path.Combine(HttpContext.Current.Server.MapPath("~/GoogleDriveFiles"),
                Path.GetFileName(file.FileName));
                file.SaveAs(path);

                Google.Apis.Drive.v3.Data.File FileMetaData = new Google.Apis.Drive.v3.Data.File();
                FileMetaData.Name = Path.GetFileName(file.FileName);
                FileMetaData.MimeType = MimeMapping.GetMimeMapping(path);

                Google.Apis.Drive.v3.FilesResource.CreateMediaUpload request;

                using (var stream = new System.IO.FileStream(path, System.IO.FileMode.Open))
                {
                    request = service.Files.Create(FileMetaData, stream, FileMetaData.MimeType);
                    request.Fields = "id";
                    request.Upload();
                }
            }
        }
        public static List<GoogleDriveFiles> GetDriveFolders()
        {
            Google.Apis.Drive.v3.DriveService service = GetService_v3();
            List<GoogleDriveFiles> FolderList = new List<GoogleDriveFiles>();

            Google.Apis.Drive.v3.FilesResource.ListRequest request = service.Files.List();
            request.Q = "mimeType='application/vnd.google-apps.folder'";
            request.Fields = "files(id, name)";

            Google.Apis.Drive.v3.Data.FileList result = request.Execute();
            foreach (var file in result.Files)
            {
                GoogleDriveFiles File = new GoogleDriveFiles
                {
                    Id = file.Id,
                    Name = file.Name,
                    Size = file.Size,
                    Version = file.Version,
                    CreatedTime = file.CreatedTime
                };
                FolderList.Add(File);
            }
            return FolderList;
        }
        public static string MoveFiles(String fileId, String folderId)
        {
            Google.Apis.Drive.v3.DriveService service = GetService_v3();

            // Retrieve the existing parents to remove
            Google.Apis.Drive.v3.FilesResource.GetRequest getRequest = service.Files.Get(fileId);
            getRequest.Fields = "parents";
            Google.Apis.Drive.v3.Data.File file = getRequest.Execute();
            string previousParents = String.Join(",", file.Parents);
            
            // Move the file to the new folder
            Google.Apis.Drive.v3.FilesResource.UpdateRequest updateRequest = service.Files.Update(new Google.Apis.Drive.v3.Data.File(), fileId);
            updateRequest.Fields = "id, parents";
            updateRequest.AddParents = folderId;
            updateRequest.RemoveParents = previousParents;
            
            file = updateRequest.Execute();
            if (file != null) {
                return "Success";
            }
            else {
                return "Fail";
            }
        }
        public static string CopyFiles(String fileId, String folderId)
        {
            Google.Apis.Drive.v3.DriveService service = GetService_v3();

            // Retrieve the existing parents to remove
            Google.Apis.Drive.v3.FilesResource.GetRequest getRequest = service.Files.Get(fileId);
            getRequest.Fields = "parents";
            Google.Apis.Drive.v3.Data.File file = getRequest.Execute();

            // Copy the file to the new folder
            Google.Apis.Drive.v3.FilesResource.UpdateRequest updateRequest = service.Files.Update(new Google.Apis.Drive.v3.Data.File(), fileId);
            updateRequest.Fields = "id, parents";
            updateRequest.AddParents = folderId;
            //updateRequest.RemoveParents = previousParents;
            file = updateRequest.Execute();
            if (file != null)
            {
                return "Success";
            }
            else
            {
                return "Fail";
            }
        }
    }
}

Step 5 (Controller): Add a controller class (HomeController.cs) under this controller folder.

                        

Copy & Paste this code within this controller:
using GoogleDriveRestAPI_v3.Models;
using System;
using System.Web;
using System.Web.Mvc;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace GoogleDriveRestAPI_v3.Controllers
{
    public class HomeController : Controller
    {
        [HttpGet]
        public ActionResult GetGoogleDriveFiles()
        {
            return View(GoogleDriveFilesRepository.GetDriveFiles());
        }

        [HttpGet]
        public ActionResult GetContainsInFolder(string folderId)
        {
            return View(GoogleDriveFilesRepository.GetContainsInFolder(folderId));
        }

        [HttpPost]
        public ActionResult CreateFolder(String FolderName)
        {
            GoogleDriveFilesRepository.CreateFolder(FolderName);
            return RedirectToAction("GetGoogleDriveFiles");
        }

        [HttpPost]
        public ActionResult UploadFile(HttpPostedFileBase file)
        {
            GoogleDriveFilesRepository.FileUpload(file);
            return RedirectToAction("GetGoogleDriveFiles");
        }

        [HttpGet]
        public JsonResult FolderLists()
        {
            List<GoogleDriveFiles> AllFolders = GoogleDriveFilesRepository.GetDriveFolders();
            List<DDLOptions> obj = new List<DDLOptions>();

            foreach (GoogleDriveFiles EachFolder in AllFolders)
            {
                obj.Add(new DDLOptions { Id = EachFolder.Id, Name = EachFolder.Name });
            }
            return Json(obj, JsonRequestBehavior.AllowGet);
        }

        public string MoveFiles(String fileId, String folderId)
        {
            string Result = GoogleDriveFilesRepository.MoveFiles(fileId, folderId);
            return Result;
        }

        public string CopyFiles(String fileId, String folderId)
        {
            string Result = GoogleDriveFilesRepository.CopyFiles(fileId, folderId);
            return Result;
        }

        public JsonResult Render_GetGoogleDriveFilesView()
        {
            Dictionary<string, object> jsonResult = new Dictionary<string, object>();
            var result = GoogleDriveFilesRepository.GetDriveFiles();
            jsonResult.Add("Html", RenderRazorViewToString("~/Views/Home/GetGoogleDriveFiles.cshtml", result));
            return Json(jsonResult, JsonRequestBehavior.AllowGet);
        }

        public string RenderRazorViewToString(string viewName, object model)
        {
            if (model != null)
            {
                ViewData.Model = model;

            }
            using (var sw = new StringWriter())
            {
                var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
                var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
                viewResult.View.Render(viewContext, sw);
                viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View);
                return sw.GetStringBuilder().ToString();
            }
        }
    }
}

Step 6 (View): We need to create two views, the First view for showing the root directory contains Google drive & second view is for showing inner file & folder structure of a particular folder.

View 1: Add a View (View Name: GetGoogleDriveFiles.cshtml) of GetGoogleDriveFiles action method.

Copy & Paste this code within this View:
@model IEnumerable<GoogleDriveRestAPI_v3.Models.GoogleDriveFiles>
@{
   ViewBag.Title = "Google Drive API v3 - ASP.NET MVC 5 [Everyday Be Coding]";
}
 <div id="Render_GetGoogleDriveFilesView">
        <h2 class="imagetable">Google Drive API v3 - [Root Directory]</h2>
        
        <center>
            <div style="width:100%;">
                <table class="imagetable">
                    <tr>
                        <td>
                            @using (Html.BeginForm("CreateFolder", "Home", FormMethod.Post))
                            {
                                <p>
                                    Folder Name :<input type="text" name="FolderName" id="txtFolderName" style="align-content:center" />
                                    <input type="submit" class="CreateFolder" value="Create Folder" style="align-content:center" />
                                </p>
                            }
                        </td>
                        <td>
                            @using (Html.BeginForm("UploadFile", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
                            {
                                <label>File Upload in Root :</label>
                                <input type="file" name="file" id="file" style="width:176px;" />
                                <input type="submit" value="Upload" />
                            }
                        </td>
                    </tr>
                </table>
            </div>
            <br />

            <table class="imagetable">
                <tr id="header">
                    <th>
                        @Html.DisplayNameFor(model => model.Name)
                    </th>
                    <th>
                        Type
                    </th>

                    <th>
                        Created Time
                    </th>
                    
                    <th>
                        Move To
                    </th>

                    <th>
                        Copy To
                    </th>
                    
                </tr>

                @if (Model.Count() > 0)
                {
                    foreach (var item in Model)
                    {
                        if (item.Parents[0] == "0ANNR3nwrf6gUUk9PVA")
                        {
                            <tr>
                                @{
                                    string FileSize = string.Empty;
                                    string Type = string.Empty;
                                    if (@item.Size != null)
                                    {
                                        long? KiloByte = @item.Size;
                                        FileSize = KiloByte + " bytes";
                                    }
                                    else
                                    {
                                        FileSize = "0 bytes";
                                    }
                                }
                                <td>
                                    @if (@item.Size == null)
                                    {
                                        <a href="@Url.Action("GetContainsInFolder", "Home", new { folderId = item.Id })">@item.Name</a>
                                    }
                                    else
                                    { @item.Name }
                                </td>

                                <td>
                                    @{
                            if (FileSize == "0 bytes") { Type = "Folder"; }
                            else { Type = "File"; }
                                    }
                                    @Type
                                </td>
                                <td>
                                    @string.Format("{0: MM/dd/yyyy}", Convert.ToDateTime(Html.DisplayFor(modelItem => item.CreatedTime).ToString()))
                                </td>
                                <td>
                                    <select id="drpGetDriveFoldersForMove" class="FolderListForMove" data-key="@item.Id">
                                        <option>Select</option>
                                    </select>
                                </td>
                                <td>
                                    <select id="drpGetDriveFoldersForCopy" class="FolderListForCopy" data-key="@item.Id">
                                        <option>Select</option>
                                    </select>
                                </td>
                            </tr>
                        }
                    }
                }
                else
                {
                    <tr> <td colspan="6">No Records found</td> </tr>
                }
            </table>
        </center>
    </div>

   <script>
         $(document).ready(function () {
             $.getJSON("/Home/FolderLists", function (data) {
                 $.each(data, function (i, data) {
                     $('<option>',
                        {
                            value: data.Id,
                            text: data.Name
                        }).html(data.Name).appendTo(".FolderListForMove");

                     $('<option>',
                       {
                           value: data.Id,
                           text: data.Name
                       }).html(data.Name).appendTo(".FolderListForCopy");
                 });
             })
         });

         $(document).on('change', '.FolderListForMove', function () {
            var FolderId = $(this).val().trim();
            var FileId = $(this).attr("data-key");

            MoveFiles(FileId, FolderId);
        });

         $(document).on('change', '.FolderListForCopy', function () {
            var FolderId = $(this).val().trim();
            var FileId = $(this).attr("data-key");

            CopyFiles(FileId, FolderId);
        });

        function MoveFiles(FileId, FolderId) {
            $.ajax({
                url: '/Home/MoveFiles',
                type: "GET",
                contentType: "application/json",
                data: { fileId: FileId, folderId: FolderId },
                success: function (result) {
                    ReloadView();
                }
            });
        }

        function CopyFiles(FileId, FolderId) {
            $.ajax({
                url: '/Home/CopyFiles',
                type: "GET",
                contentType: "application/json",
                data: { fileId: FileId, folderId: FolderId },
                success: function (result) {
                    ReloadView();
                }
            });
        }
        
        function ReloadView() {
            $("#Render_GetGoogleDriveFilesView").html("<center><img src='../../Images/ajax-loading.gif' alt='Loading...' /></center>");
            $.ajax({
                url: "/Home/Render_GetGoogleDriveFilesView",
                type: "POST",
                contentType: "application/json",
                success: function (data) {
                    $("#Render_GetGoogleDriveFilesView").html(data.Html);
                }
            });
        }

    </script>

View 2: Add a View (View Name: GetContainsInFolder.cshtml) of GetContainsInFolder() action method.

Copy & Paste this code within this View:
@model IEnumerable<GoogleDriveRestAPI_v3.Models.GoogleDriveFiles>
<center>
    <br><br>
    @if (Model.Count() > 0)
    {
        <table class="imagetable">
            <tr>
            <th>
                @Html.DisplayNameFor(model => model.Name)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Size)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Version)
            </th>
            <th>
                Created Time
            </th>

            @foreach (var item in Model)
            {
                string FileSize = string.Empty;
                string Type = string.Empty;
                if (@item.Size != null)
                {
                    long? KiloByte = @item.Size;
                    FileSize = KiloByte + " bytes";
                }
                <tr>
                    <td>
                        @Html.DisplayFor(modelItem => item.Name)
                    </td>
                    <td>
                        @FileSize
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Version)
                    </td>
                    <td>
                        @string.Format("{0: MM/dd/yyyy}", Convert.ToDateTime(Html.DisplayFor(modelItem => item.CreatedTime).ToString()))
                    </td>
                </tr>
            }
        </table>
    }
    else
    {
        <table class="imagetable">
            <tr>
                <th>
                    @Html.DisplayNameFor(model => model.Name)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Size)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Version)
                </th>
                <th>
                    Created Time
                </th>
            </tr>
        <tr><td colspan="6">No records found</td></tr>
        </table>
    }

   @Html.ActionLink("Back", "GetGoogleDriveFiles")
</center>

Shared View 3: Add a View (View Name: _Layout.cshtml

Copy & Paste this code within this View:
<!DOCTYPE html>
<html>
<head>
    <style type="text/css">
        table.imagetable {
            font-family: verdana,arial,sans-serif;
            font-size: 11px;
            color: #333333;
            border-width: 1px;
            border-color: #999999;
            border-collapse: collapse;
        }

            table.imagetable th {
                background: #b5cfd2 url('cell-blue.jpg');
                border-width: 1px;
                padding: 8px;
                border-style: solid;
                border-color: #999999;
            }

            table.imagetable td {
                /*background: #dcddc0 url('cell-grey.jpg');*/
                border-width: 1px;
                padding: 8px;
                border-style: solid;
                border-color: #999999;
            }
    </style>
    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
</head>
<body>
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                @Html.ActionLink("Cloud Storage Access through API - ASP.NET MVC 5 - C#", "GetGoogleDriveFiles", "Home", null, new { @class = "navbar-brand" })
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                </ul>
            </div>
        </div>
    </div>

    <div class="container body-content">
        @RenderBody()
    </div>
</body>
</html>

Step 7 : Change the default action method name 'Index' to  'GetGoogleDriveFiles'.

using System.Web.Mvc;
using System.Web.Routing;

namespace GoogleDriveRestAPI_v3
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "GetGoogleDriveFiles", id = UrlParameter.Optional }
            );
        }
    }
}

Thank you for reading this blogs. 
Please subscribe my YouTube Channel & don't forget to like and share. 

YouTube :https://goo.gl/rt4tHH
Facebook :https://goo.gl/hgpQsh
Twitter :https://goo.gl/nUwGnf

Comments

Popular posts from this blog

Cloud Storage Access through API  - Advanced Developer Guide - C#  1. Google Drive API - Enable & Get Client Credentials for Application 2. Google Drive API - Uploading, Viewing, Downloading & Deleting Files 3. Google Drive API - Create folder, Upload file to folder, Show folder Content. 4. Google Drive API - How to Move & Copy Files Between Folders. 5. Google Drive API - How to Share & Set Permission of File/Folders. 6. Google Drive API - View Share Users Permission Details. 7. Google Picker API - Viewing, Uploading, Downloading, Sharing. ASP.NET  MVC Tutorial - Advanced Developer Guide - C#  How to Export Razor View to Excel file (Without using Third-Party Library). Excel Development using EPPlus Library Beginners Guide - C# 1. Create an Excel File using EPPlus .Net Library. 2. Apply Cell text and Background Color in Excel Sheet. 3. Apply Cell Border Style in Excel Sheet. 4. Apply Cell Text Alignment, Row Height, Column Width in Excel Sheet

Google Drive API using JavaScript | Full Project - Overview

Setup Google Developer Console for Google Drive API Applications using J...