I am new to Telerik controls, in my code I am trying to Upload excel file using RadAsync upload.
Code is working fine, but when user is trying to upload a file which is already opened in the background- I am getting javascript exception.
Is there is any way by which I can alert user in case file is already opened?
You can use OnClientFileUploadFailed event of Telerik RadAsync Upload.
Something like
function OnClientFileUploadFailed(sender, args) {
var upload = $find("<%= RadUpload.ClientID %>");
var errormsg = args.get_message();
var displaymsg = new String();
sender.deleteFileInputAt(0);
if (errormsg.search("[IO.IO_SharingViolation_File]") != -1) {
displaymsg = "File: is currently in use. Please close the file and try again.";
}
else {
displaymsg = "The file you selected is currently in use. Please close the file and try again.";
}
alert(displaymsg);
args.set_handled(true);
}
Related
I'm working in a UWP app, at some point, the user has the chance to save an image (done) by now I only let the user know that the save operation was done by a "messageDialog", this is my code:
var savePicker = new Windows.Storage.Pickers.FileSavePicker();
savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
savePicker.FileTypeChoices.Add("QR Code", new List<string>() { ".png", ".jpg", ".jpeg", ".jpe", ".bmp" });
savePicker.SuggestedFileName = "QR_01";
Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync();
if (file != null)
{
Windows.Storage.CachedFileManager.DeferUpdates(file);
await Windows.Storage.FileIO.WriteBytesAsync(file, _bytes3);
Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file);
if (status == Windows.Storage.Provider.FileUpdateStatus.Complete)
{
var messageDialog = new Windows.UI.Popups.MessageDialog("File saved on: " + file.Path);
await messageDialog.ShowAsync();
}
else
{
//this.textBlock.Text = "File " + file.Name + " couldn't be saved."; not defined by now
}
done = true;
}
else
{
this.textBlock.Text = "operation canceled";
done = false;
}
This works good so far but I want to be sure that the file is already there after the "WriteBytesAsync" method. So, this is the thing, the users can save the image in any directory they have acces to so I can't check (or read) the folder they choose afer that because I don't have acces permission afer save the file. I have tryed something like this to get folder access:
string savePath = System.IO.Path.GetDirectoryName(file.Path);
Windows.Storage.StorageFolder saveFolder = await Windows.Storage.StorageFolder.GetFolderFromPathAsync(savePath);
In order to use the "GetFileAsync" to check the file or the "FutureAccessList" for a future access but since I have file access permisions to any directory it fails, and because of that I can't use any of the solution in here: UWP Check If File Exists
My Questions are:
1.- Is there a way to check if the file was saved or successfully written afer the user click the "Save" button?
2.- Does the "WriteBytesAsync" method is enough to ensure taht the file was saved?? according to the info FileIO.WriteBytesAsync(IStorageFile, Byte[]) Method, it don't throw any exception.
but I want to be sure that the file is already there after the "WriteBytesAsync" method.
For you requirement, you could use GetFileFromPathAsync method to get the file, if the file is not null, means that the file is exist. And please note if you want to above method, you need add broadFileSystemAccess capability, and open it in your system setting. For more please refer this.
Windows.Storage.CachedFileManager.DeferUpdates(file);
await Windows.Storage.FileIO.WriteBytesAsync(file, new byte[3]);
var temp = await StorageFile.GetFileFromPathAsync(file.Path);
if(temp != null)
{
}
else
{
}
Does the "WriteBytesAsync" method is enough to ensure taht the file was saved??
Yep, WriteBytesAsync method need to pass StorageFile parameter. if the file parameter is not null means it has created in the folder. Or it will throw null exception.
I'm just trying to check browser compatibility with images and videos in the Reactjs website application. If the extension of the image/video does not support, then it has to show a alert message or an action. how to do this ?
Tried Modernizr
I tried, the given code is working for me :
videoBrowserSupportValidation() {
const extension = filename.split('.').pop(); // This is to get extenstion of your video file and filename is video file name
const vidpath1 = "video/";
var obj = document.createElement('video');
var videoType = obj.canPlayType(vidpath1+extension);
if (videoType == "") {
console.log("Invalid file , browser does not recognize video formats ");
// write your action
}
else {
console.log("Valid file");
// write your action
}
I have made a winform application. When I run the app in visual studio, following code works to open a link from DataGridView link column.
System.Diagnostics.Process.Start("chrome.exe",
grdRelLinks.Rows[e.RowIndex].Cells[2].Value.ToString());
But when I install the build and try to do the same thing, nothing happens. Is there any other setting that I need to make.
Please help.
If you want to open link link from your DataGridView, you should actually pass url not web browser, ie.:
System.Diagnostics.Process.Start(grdRelLinks.Rows[e.RowIndex].Cells[2].Value.ToString());
It will end up trying to open given url with default browser for OS.
Ofc make sure that link of url from url is properly formatted.
If chrome.exe doesn't work for launching, maybe try shortened one: chrome?
Can you also confirm that Win+R (a.k.a. Run...) and then chrome.exe actually opens up Chrome?
If not, can you check if
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ contains chrome.exe entry?
If so, maybe url formatting is wrong?
You can open a URL in browser with the following snippets:
Process process = new Process();
process.StartInfo.UseShellExecute = true;
process.StartInfo.FileName = "http://google.com";
process.Start();
or
System.Diagnostics.Process.Start("http://google.com");
In your example, to allow users to launch it from the DataGridView, you should simply define a click event like this:
private void grdRelLinks_CellContentClick(object pSender, DataGridViewCellEventArgs pArgs)
{
if (pArgs.RowIndex > -1 && pArgs.ColumnIndex == 2)
{
string url = grdRelLinks.Rows[pArgs.RowIndex].Cells[pArgs.ColumnIndex].Value.ToString();
if(!string.IsNullOrWhiteSpace(url))
System.Diagnostics.Process.Start(url);
}
}
This worked for me.
private void OnGridViewContentClick(object sender, EventArgs e)
{
string chromeExePath = CheckIfChromeIsInstalled();
if (!string.IsNullOrEmpty(chromeExePath))
{
MessageBox.Show("Yayy Chrome.exe was found !");
//Path is not null:
Process.Start(chromeExePath, "http://www.google.de");//Here you can also enter the URL you get from your GridView
string url = grdRelLinks.Rows[e.RowIndex].Cells[2].Value.ToString();
if(!url.StartsWith("http")
{
url = $"http://{url}";
}
Process.Start(chromeExePath, url);
}
else
{
MessageBox.Show("Chrome.exe not found");
}
}
private string CheckIfChromeIsInstalled()
{
DirectoryInfo programFiles = new DirectoryInfo(Environment.GetEnvironmentVariable("PROGRAMFILES"));//Find your Programs folder
DirectoryInfo[] dirs = programFiles.GetDirectories();
List<FileInfo> files = new List<FileInfo>();
Parallel.ForEach(dirs, (dir) =>
{
files.AddRange(dir.GetFiles("chrome.exe", SearchOption.AllDirectories)); //Search for Chrome.exe
});
//files should only contain 1 entry
//Return path of chrom.exe or null
return (files.Count > 0) ? files[0].FullName : null;
}
NOTE: Starting this in an extra Thread could be useful !
EDIT :
Can you please check if cmd.exe works with start chrome.exe "your URL" ?!
I want to be able to open a PDF using the native Windows Reader Application when a user clicks on a button. So far I am able to use the following code to successfully open files that end with the (.PNG) extension. However, when I let the link to open the (.PDF) file I get the following error.
The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
The file destination is correct.
Here is my code:
private async void btnLoad_Click(object sender, RoutedEventArgs e)
{
// Path to the file in the app package to launch
string imageFile = #"Data\Healthcare-Flyer.pdf";
var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile);
if (file != null)
{
// Set the option to show the picker
var options = new Windows.System.LauncherOptions();
options.DisplayApplicationPicker = true;
// Launch the retrieved file
bool success = await Windows.System.Launcher.LaunchFileAsync(file, options);
if (success)
{
// File launched
}
else
{
// File launch failed
}
}
else
{
// Could not find file
}
}
}
When you add PDF document in project, you have to change it's build action.
Right click on PDF document.
Click on properties.
Change Build Action from None to Content
A while back I wrote a silverlight user control which had a csv import/export feature. This has been working fine, until recently I discovered it erroring in one scenario. This may have been due to moving to Silverlight 3.
The Error:
Message: Unhandled Error in Silverlight 2 Application
Code: 4004
Category: ManagedRuntimeError
Message: System.Security.SecurityException: Dialogs must be user-initiated.
at System.Windows.Controls.OpenFileDialog.ShowDialog()
at MyControl.OpenImportFileDialog()
at ...
The Code:
private void BrowseFileButton_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(lblFileName.Text))
{
if (MessageBox.Show("Are you sure you want to change the Import file?", "Import", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
{
return;
}
}
EnableDisableImportButtons(false);
var fileName = OpenImportFileDialog();
lblFileName.Text = fileName ?? string.Empty;
EnableDisableImportButtons(true);
}
private string OpenImportFileDialog()
{
var dlg = new OpenFileDialog { Filter = "CSV Files (*.csv)|*.csv" };
if (dlg.ShowDialog() ?? false)
{
using (var reader = dlg.File.OpenText())
{
string fileName;
//process the file here and store fileName in variable
return fileName;
}
}
}
I can open an import file, but if i want to change the import file, and re-open the file dialog, it errors. Does anyone know why this is the case?
Also, I am having trouble debugging because placing a breakpoint on the same line (or prior) to the dlg.ShowDialog() call seems to cause this error to appear as well.
Any help would be appreciated?
You do two actions on one user click.
You show a messagebox which effectively uses your permission to show a dialog on user action.
You then try to show the dialog, since this is a second dialog on user action it's not allowed.
Get rid of the confirmation dialog and you'll be fine.
Remove Break Points before if (dlg.ShowDialog() ?? false) code will run its work for me.