|
<EjsFileManager RootAliasName="Root Folder">
<FileManagerAjaxSettings Url="/api/Default/SQLFileOperations"
GetImageUrl="/api/Default/SQLGetImage"
UploadUrl="/api/Default/SQLUpload"
DownloadUrl="/api/Default/SQLDownload">
</FileManagerAjaxSettings>
</EjsFileManager> |
|
<EjsFileManager RootAliasName="Root Folder">
<FileManagerEvents ToolbarItemClicked="toolbarClick"></FileManagerEvents>
<FileManagerToolbarSettings Items="@ToolbarItems"></FileManagerToolbarSettings>
</EjsFileManager>
public string[] ToolbarItems = new string[] {"NewFolder", "Upload", "Delete", "Download", "Rename", "SortBy", "Refresh", "Selection", "View", "Details", "Custom"};
public void toolbarClick(ToolbarClickEventArgs args)
{
if(args.Item.Text == "Custom")
{
// Perform the operation based on your requirement.
System.Diagnostics.Debug.Write("Custom item clicked");
}
} |
|
<EjsFileManager RootAliasName="Root Folder">
<FileManagerEvents ToolbarItemClicked="toolbarClick" OnMenuClick="menuClick"></FileManagerEvents> <FileManagerContextMenuSettings File="@Items" Folder="@Items"></FileManagerContextMenuSettings>
</EjsFileManager>
public string[] Items = new string[] { "Open", "|", "Delete", "Download", "Rename", "|", "Details", "Custom" };
public void menuClick(MenuClickEventArgs args)
{
if(args.Item.Text == "Custom")
{
// Perform the operation based on your requirement.
System.Diagnostics.Debug.Write("Custom item clicked");
}
} |
|
public class DefaultController : Controller
{
public PhysicalFileProvider operation;
public string basePath;
// Based on Login id.
if(option1 == "user1") {
string root = "wwwroot\\Files";
}
else if(option1 == "user2") {
string root = "wwwroot\\Files\\Data";
}
} |
|
public async Task menuClick(MenuClickEventArgs args)
{
if(args.Item.Text == "Custom")
{
var selectedFiles = await file.GetSelectedFiles();
// Perform the operation based on your requirement.
System.Diagnostics.Debug.WriteLine("Custom item clicked");
}
} |
|
public DefaultController (IHostingEnvironment hostingEnvironment)
{
// You can set rules for folder access.
this.operation.SetRules(GetRules());
}
public AccessDetails GetRules()
{
AccessDetails accessDetails = new AccessDetails();
List
// For Default User
new AccessRule { Path = "/Documents", Role = "Document Manager", Read = Permission.Deny, Write = Permission.Deny, Copy = Permission.Allow, WriteContents = Permission.Allow, Upload = Permission.Allow, Download = Permission.Deny },
};
accessDetails.AccessRules = folderRule;
accessDetails.Role = "Document Manager";
return accessDetails;
} |
|
public object getFiles(FileManagerDirectoryContent args)
{
FileResponse readResponse = new FileResponse();
try
{
// Get the Files details of all the files in FileManager component.
var value = this.operation.GetFiles(args.Path, args.ShowHiddenItems, args.Data);
DirectoryContent cwd = new DirectoryContent();
readResponse.CWD = JsonConvert.DeserializeObject<DirectoryContent>(JsonConvert.SerializeObject(value.CWD));
SqlConnection sqlConnection = new SqlConnection(this.operation.ConnectionString);
try
{
sqlConnection.Open();
// add the ReviewNumber column to the response.
readResponse.CWD.ReviewNumber = value.CWD.Id;
}
catch (SqlException ex) { Console.WriteLine(ex.ToString()); }
finally { sqlConnection.Close(); }
readResponse.Files = JsonConvert.DeserializeObject<IEnumerable<DirectoryContent>>(JsonConvert.SerializeObject(value.Files));
// add the ReviewNumber field to the each files and folder.
foreach (DirectoryContent file in readResponse.Files)
{
SqlConnection sqlConnection1 = new SqlConnection(this.operation.ConnectionString);
try
{
sqlConnection1.Open();
file.ReviewNumber = file.ReviewNumber;
}
catch (SqlException ex) { Console.WriteLine(ex.ToString()); }
finally { sqlConnection1.Close(); }
}
readResponse.Details = value.Details;
readResponse.Error = value.Error;
// Return the Read response to the FileManager component.
return readResponse;
}
catch (SqlException ex) { return null; }
} |
|
try
{
...
...
{
ReviewNumber = reader["ReviewNumber"].ToString(),
HasChild = (bool)reader["HasChild"]
};
...
...
while (reader.Read())
{
var childFiles = new FileManagerDirectoryContent
{
ReviewNumber = reader["ReviewNumber"].ToString(),
Id = reader["ItemID"].ToString()
};
...
...
files.Add(childFiles);
}
} |
|
<SfFileManager RootAliasName="Root Folder">
<FileManagerDetailsViewSettings >
<FileManagerColumns>
<FileManagerColumn Field="name" HeaderText="FileName"></FileManagerColumn>
<FileManagerColumn Field="dateModified" HeaderText="Date Modified">
</FileManagerColumn>
<FileManagerColumn Field="reviewNumber" HeaderText="ReviewNumber">
</FileManagerColumn>
</FileManagerColumns>
</FileManagerDetailsViewSettings>
</SfFileManager> |
|
<SfDropDownList @ref="Dropdown" Value="@dropValue" TValue="string" TItem="Games" Placeholder="Select a game" DataSource="@LocalData">
<DropDownListEvents TValue="string" ValueChange="change"></DropDownListEvents>
<DropDownListFieldSettings Value="ID" Text="Text"></DropDownListFieldSettings>
</SfDropDownList>
public void change(ChangeEventArgs<string> args)
{
// Refresh the FileManager component. It Triggers the onSend event in FileManager component.
this.Filemanager.Refresh();
} |
|
<SfFileManager @ref="Filemanager">
<FileManagerEvents OnSend="send"></FileManagerEvents>
</SfFileManager>
public void send(BeforeSendEventArgs args)
{
// Add the extra column in AhaxSettings of Filemanager and send the value to the FileManager component.
string AjaxSettingsString = JsonConvert.SerializeObject(args.AjaxSettings);
Dictionary<string, dynamic> AjaxSettings = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(AjaxSettingsString);
string dataString = AjaxSettings["data"];
Dictionary<string, dynamic> data = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(dataString);
// Fetch the DropDown value.
var Option = this.Dropdown.Value;
data.Add("Option", Option);
string modifiedDataString = JsonConvert.SerializeObject(data);
AjaxSettings["data"] = modifiedDataString;
string returnString = JsonConvert.SerializeObject(AjaxSettings);
args.AjaxSettings = JsonConvert.DeserializeObject<object>(returnString);
} |
|
[Route("SQLFileOperations")]
public object SQLFileOperations([FromBody] FileManagerDirectoryContent1 args)
{
if(args.Option == "Option1")
{
operation.SetSQLConnection("FileManagerConnection", "Product", "0");
}
else if(args.Option == "Option2") {
// Set the path based on your requirement.
}
} |
|
public async void fileLoad(FileLoadEventArgs args)
{
string dataString = JsonConvert.SerializeObject(args.FileDetails);
Dictionary<string, dynamic> fileDetails = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(dataString);
if (args.Module == "LargeIconsView" && (fileDetails["type"] == ".pptx" || fileDetails["type"] == ".docx"
|| fileDetails["type"] == ".doc" || fileDetails["type"] == ".rtf" || fileDetails["type"] == ".pdf"))
{
// Get the URL of the files.
string url = getImageUrl(fileDetails);
DOM ele = args.Element;
string val = Convert.ToString((await ele.GetAttribute("data-uid")));
ele.AddClass(new string[] { "e-file-preview-image" });
// Call the client side function.
await JSRuntime.InvokeVoidAsync("setPreview", val, url);
}
}
public string getImageUrl(Dictionary<string, dynamic> data)
{
//Specify your controller action name
string baseUrl = "/api/Default/GetPreviewImage";
string imgUrl = baseUrl + "?path=" + data["filterPath"] + data["name"];
return imgUrl;
}
} |
|
[Route("GetPreviewImage")]
public IActionResult GetPreviewImage(FileManagerDirectoryContent args)
{
try
{
String fullPath = baseFolder + args.Path;
string extension = Path.GetExtension(fullPath);
Stream imageStream = null;
if (extension == ".pdf")
{
FileStream fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read);
PdfRenderer pdfExportImage = new PdfRenderer();
//Loads the PDF document
pdfExportImage.Load(fileStream);
//Exports the PDF document pages into images
Bitmap[] bitmapimage = pdfExportImage.ExportAsImage(0, 0);
imageStream = new MemoryStream();
bitmapimage[0].Save(imageStream, System.Drawing.Imaging.ImageFormat.Png);
imageStream.Position = 0;
pdfExportImage.Dispose();
fileStream.Close();
}
else if (extension == ".docx" || extension == ".rtf" || extension == ".doc")
{
FileStream fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read);
//Loads file stream into Word document
WordDocument document = new WordDocument(fileStream, Syncfusion.DocIO.FormatType.Automatic);
fileStream.Dispose();
//Instantiation of DocIORenderer for Word to PDF conversion
DocIORenderer render = new DocIORenderer();
//Converts Word document into PDF document
PdfDocument pdfDocument = render.ConvertToPDF(document);
//Releases all resources used by the Word document and DocIO Renderer objects
render.Dispose();
document.Dispose();
//Saves the PDF file
MemoryStream outputStream = new MemoryStream();
pdfDocument.Save(outputStream);
outputStream.Position = 0;
//Closes the instance of PDF document object
pdfDocument.Close();
PdfRenderer pdfExportImage = new PdfRenderer();
//Loads the PDF document
pdfExportImage.Load(outputStream);
//Exports the PDF document pages into images
Bitmap[] bitmapimage = pdfExportImage.ExportAsImage(0, 0);
imageStream = new MemoryStream();
bitmapimage[0].Save(imageStream, System.Drawing.Imaging.ImageFormat.Png);
imageStream.Position = 0;
fileStream.Close();
}
else if (extension == ".ppt" || extension == ".pptx")
{
IPresentation presentation = Presentation.Open(fullPath);
//Initialize PresentationRenderer for image conversion
presentation.PresentationRenderer = new PresentationRenderer();
//Convert the first slide to image
imageStream = presentation.Slides[0].ConvertToImage(ExportImageFormat.Png);
presentation.Dispose();
}
FileStreamResult fileStreamResult = new FileStreamResult(imageStream, "APPLICATION/octet-stream");
//Retur the image result.
return fileStreamResult;
}
catch (Exception e)
{
return null;
}
} |
|
<SfFileManager TValue="DirectoryContent" View="ViewType.Details">
<FileManagerEvents TValue="DirectoryContent"></FileManagerEvents>
<FileManagerDetailsViewSettings>
<FileManagerColumns>
<FileManagerColumn Field="Name" HeaderText="FileName"></FileManagerColumn>
<FileManagerColumn Field="DateModified" HeaderText="Date Modified">
</FileManagerColumn>
<FileManagerColumn Field="UrlValue">
<HeaderTemplate>
<span>URL Name</span>
</HeaderTemplate>
<Template>
@{
var data = (context as DirectoryContent);
<div>@data.UrlValue</div>
}
</Template>
</FileManagerColumn>
</FileManagerColumns>
</FileManagerDetailsViewSettings>
<FileManagerAjaxSettings Url="/api/Home/FileOperations"
UploadUrl="/api/Home/Upload"
DownloadUrl="/api/Home/Download"
GetImageUrl="/api/Home/GetImage">
</FileManagerAjaxSettings>
</SfFileManager>
@code{
public class DirectoryContent
{
...
…
public string URL { get; set; }
public string UrlValue { get; set; }
}
}
Controller
switch (args.Action)
{
case "read":
// reads the file(s) or folder(s) from the given path.
return this.getFiles(args);
}
public object getFiles(FileManagerDirectoryContent args)
{
FileResponse readResponse = new FileResponse();
try
{
var value = this.operation.GetFiles(args.Path, args.ShowHiddenItems);
DirectoryContent cwd = new DirectoryContent();
readResponse.CWD = JsonConvert.DeserializeObject<DirectoryContent>(JsonConvert.SerializeObject(value.CWD));
readResponse.CWD.URL = "https://github.com/SyncfusionExamples/ej2-aspcore-file-provider";
readResponse.Files = JsonConvert.DeserializeObject<IEnumerable<DirectoryContent>>(JsonConvert.SerializeObject(value.Files));
//Add the additional parameter for each files in filemanager component.
foreach (DirectoryContent file in readResponse.Files)
{
//Add the URL as additional parameter.
file.URL = "https://www.google.com/";
// Add the URL value as addittiona parameter.
file.UrlValue = "Google";
}
readResponse.Details = value.Details;
readResponse.Error = value.Error;
return readResponse;
}
catch
{
ErrorDetails er = new ErrorDetails();
}
return this.operation.ToCamelCase(this.operation.GetFiles(args.Path, args.ShowHiddenItems));
} |