public
string
ParentPath {
get
;
set
; }
public
string
Name {
get
;
set
; }
public
int
Type {
get
;
set
; }
public
FolderFiles[] SubFolder {
get
;
set
; }
//ItemID is required only in case of Google Drive
public
string
ItemID {
get
;
set
; }
public
FolderFiles()
ParentPath =
null
;
public
async
Task<List<FolderFiles>> GetCloudData(
string
cloudName)
var
applicationInitPath =
"FolderName"
;
// Initial path from where file list should be fetched
string
authority = System.Web.HttpContext.Current.Request.Url.Authority;
string
apiUrl = authority +
"/api/storage/List"
;
string
parentPath =
"/"
+ cloudName +
"/"
+ applicationInitPath);
using
(HttpClient client =
new
HttpClient())
var
url =
new
UriBuilder(
"http://"
+ apiUrl + parentPath);
var
response =
await
client.GetAsync(url.ToString()).ConfigureAwait(
false
);
if
(response.IsSuccessStatusCode)
var
data =
await
response.Content.ReadAsStringAsync().ConfigureAwait(
false
);
var
table = Newtonsoft.Json.JsonConvert.DeserializeObject<List<FolderFiles>>(data);
foreach
(
var
row
in
table)
row.ParentPath = parentPath;
if
(row.Type == 0)
row.SubFolder =
new
FolderFiles[0];
return
table;
return
new
List<FolderFiles>();
public
async
Task< List<FolderFiles>> LazyLoading_GetCloudData(
string
subPath,
string
parentPath,
string
cloudName,
string
itemId)
string
authority = System.Web.HttpContext.Current.Request.Url.Authority;
string
apiUrl =
"http://"
+ authority +
"/api/storage/List"
;
using
(HttpClient client =
new
HttpClient())
var
url =
new
UriBuilder(apiUrl + parentPath);
if
(!
string
.IsNullOrEmpty(subPath))
url =
new
UriBuilder(url +
"/?subpath="
+ subPath);
//While working with Google drive, itemId is required to make sure in which folder is working
if
(!
string
.IsNullOrEmpty(itemId))
url =
new
UriBuilder(url +
"?itemid="
+ itemId);
var
response =
await
client.GetAsync(url.ToString()).ConfigureAwait(
false
);
if
(response.IsSuccessStatusCode)
var
data =
await
response.Content.ReadAsStringAsync().ConfigureAwait(
false
);
var
table = Newtonsoft.Json.JsonConvert.DeserializeObject<List<FolderFiles>>(data);
foreach
(
var
row
in
table)
row.ParentPath = parentPath +
"/"
+ subPath;
if
(row.Type == 0)
row.SubFolder =
new
FolderFiles[0];
return
table;
return
new
List<FolderFiles>();
function Upload() {
var
file = document.getElementById(
"file"
).files[0];
var
data =
new
FormData();
data.append(
"file"
, file);
var
url = baseUrl+
'api/storage/'
+ cloudName +
"/"
+ folderPathToUploadFile+
"/"
+ file.name;
//This code is only for using Google Drive service
if
(itemId !=
null
) {
url = url +
"?itemid="
+ itemId;
$.ajax({
url: url,
type:
'POST'
,
data: data,
cache:
false
,
contentType:
false
,
processData:
false
}).then(function (res) {
alert(
"Uploaded"
)
var
baseUrl = window.location.origin;
//"http://localhost:9272/";
function Download() {
var
url = baseUrl+
'/api/storage/'
+ cloudName +
"/"
+ folderPathToDownloadFile +
"/"
+ FileNameToDownloadwithExtension;
var
elem = wijmo.createElement(
""
);
elem.click();
var
baseUrl = window.location.origin;
//"http://localhost:9272/";
function DeleteFile() {
var
url = baseUrl+
'api/storage/'
+ cloudName +
"/"
+ folderPathToDeleteFile +
"/?subpath="
+ FileNameToDeleteWithExtn;
//This code is only for using Google Drive service
if
(itemId !=
null
) {
url = url +
"?itemid="
+ itemId;
$.ajax({
url: url,
type:
'DELETE'
,
cache:
false
,
contentType:
false
,
processData:
false
,
success: function (data, success, obj) {
alert(
"Deleted"
);
refreshTree();