Work on C# .In one of my application I need to upload file and save to database.I write a button event
private void btnUpload_Click(object sender, EventArgs e)
{
}
After button click from user defined folder path I upload file,than rest of the syntax save in database.I have done above. Now I need to know, if a file save or update or on file if user do any type of action than I need to upload that file automatically.How to automatically active any event ,plz don’t say any type of timer event.As soon as user update file I need to upload it.How can I detect user update file?How can I active event to upload the file?If have any query plz ask.Thanks in advance.Any type of suggestion will be acceptable.
You can monitor the folder using FileSystemWatcher
You can use the FileSystemWatcher. Create a new instance like that:
var fileSystemWatcher = new FileSystemWatcher(fileToWatch);
fileSystemWatcher.Changed += OnFileChanged;
And in following event you can do the upload of the file:
private void OnFileChanged(object sender, FileSystemEventArgs e)
{
// Upload e.FullPath;
}
Related
I'm currently using an ASP.NET File Upload control. This works great, but I'd like to remove the current Upload button and put its logic into the Browse... button instead.
Is there a way to overload the Browse... button's logic?
Currently:
I'd like to have this:
When the user clicks the Open button in the File Upload box, the Upload buttons' logic fires:
Upon clicking Open, the following code triggers in C# Code behind.
protected void override btnSomeOverriddenControl_Click(object sender, EventArgs e)
{
if (multipleFile.HasFiles)
{
foreach (var file in multipleFile.PostedFiles)
{
//do stuff
}
}
}
I have a hyperlink button in my Silverlight 4 application. I want to download an apk file when I click on this link. I am able to download file but my problem is that when I click on link it downloads the file and trie to navigate on that link so it shows the dialog for file download and raises an exception.
and the code behind hyperlink button is
private void hyperlinkButton1_Click(object sender, RoutedEventArgs e)
{
Uri myAbsoluteUri = new Uri(Application.Current.Host.Source,"../download/ItimHRMSAndroidApp.apk");
HtmlPage.Window.Navigate(myAbsoluteUri);
}
I just want to open the download link - not actually navigating to that page.
Set the URI within the markup:
<HyperlinkButton x:Name="MyButton" TargetName="_blank" Content="Download APK" NavigateUri="/download/ItimHRMSAndroidApp.apk" Canvas.Top="40" Canvas.Left="30"></HyperlinkButton>
And remove the Click event handler:
private void hyperlinkButton1_Click(object sender, RoutedEventArgs e)
{
Uri myAbsoluteUri = new Uri(Application.Current.Host.Source,"../download/ItimHRMSAndroidApp.apk");
HtmlPage.Window.Navigate(myAbsoluteUri);
}
Why not try using a Generic Web handler
And return the apk file
Like this post
Hope this helps.
the problem was not of the _target field. it is of the path.
I'm creating a native C# application and I need to do a simple thing:
Once the user clicks some certain button, another .cs file is opened (with its own design, code and stuff). If it is possible, I would like to know how to close the current form at the same time.
EDIT: what I exactly need:
namespace Mokesciai
{
public partial class Mokesciai : Form
{
public Mokesciai()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//write code here to open another page called "NewPage.cs" with its own subfiles "NewPage.Designer.cs" and
//"NewPage.resx", as shown in the solution explorer
}
}
}
The application is C# Windows application
EDIT2: what I want in the graphical way: http://sdrv.ms/JXKVEL
By clicking "Click me" I want to open the new form
private void button1_Click(object sender, EventArgs e)
{
YourSecondForm objForm=new YourSecondForm();
objForm.Show();
this.Close();
}
Assuming YourSecondForm is the name of your another form which you want to display on the button click event.
That is a form.
You can create a new instance of the form class, then call Show().
As far as i understand from your question, may be you want to do this. You can use Process.Start() to start any other application from your native app.
using System.Diagnostics;
string path=#"path to the app"
Process.Start(path);
OR
Create a new form place a multi line text box, then read the file using StreamReader & fill its result on the text box. For more information on how to use Stream Reader Check out this or this
Have a unique customer request which Im unsure how to tackle.
The customer has a webpage form with a browse button to select a file. When the browse button is clicked, instead of showing the local files, they want to pop-up a window with a textbox to enter a code. This code is then used to select a file from a local folder containing 1000 files each with their own code. They want to prevent the user from viewing the other files in that folder.
I did write a custom Windows form to mimic the webpage form but they already have the webpage online and would like to reuse it.
Any ideas how to intercept the browse button? I can use a C# Application with the web browser component, but can that intercept the browse button?
The only option that I can see working is using a C# Application with the web browser component. You can then use WebBrowser.ObjectForScripting to provide a method that can be called to trigger your custom picker window through Javscript, e.g:
window.external.ShowPickerWindow();
You then have two options:
Interrogate the DOM of the page once it's loaded and replace the button with one that triggers your picker window.
Have the customer change their page so it checks for the existance of a window.external.ShowPickerWindow method and basically does option (1) for you.
You can then have a method, perhaps called window.external.GetPickedCode() to pull the code out in the page.
Rob kinder steered me along the correct thinking track by saying "replace the button" which has lead me to a solution which works beautifully!
In short, I hide the browse button, insert a new button next to it that when clicked, opens a new window with a textbox. This textbox then sets a string value in the parent form which is used onSubmit to attach the file.
private void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HtmlElement btnBrowse = wb.Document.GetElementById("fiPhoto");
if (btnBrowse != null)
{
HtmlElement newbtn = wb.Document.CreateElement("input");
newbtn.SetAttribute("id", "btnLoad");
newbtn.SetAttribute("type", "button");
newbtn.SetAttribute("value", "Load");
newbtn.Click += new HtmlElementEventHandler(newbtn_Click);
btnBrowse.Parent.AppendChild(newbtn);
btnBrowse.Style = "display:none";
}
HtmlElementCollection forms = wb.Document.Forms;
if (forms.Count > 0)
{
HtmlElement form = wb.Document.Forms[0];
form.AttachEventHandler("onsubmit", delegate(object o, EventArgs arg)
{
FormToMultipartPostData postData = new FormToMultipartPostData(wb, form);
postData.AddFile("photo", photo);
postData.Submit();
});
}
}
private void newbtn_Click(object sender, EventArgs e)
{
Form2 frm = new Form2(this);
frm.ShowDialog();
}
FormToMultipartPostData is too big to post in here but it basically manually constructs the Content-Disposition to be posted
Don't show the actual file browser, imitate one which is showing only that one file in in.
Or since you know the file path when correct code is entered copy the file to temp folder you created and open file browser to browse that folder and it will be contain only that file.
Is there a way in which I can save details from a ListView that doesnt require me to use the save dialog box everytime and allows me to call it within a certain time span. So 'save' rather than 'save as' everytime.
You can use a DispatchTimer with a callback to a method to perform your save.
DispatcherTimer autosaveTimer = new DispatcherTimer(TimeSpan.FromSeconds(autosaveInterval), DispatcherPriority.Background, new EventHandler(DoAutoSave), Application.Current.Dispatcher);
private void DoAutoSave(object sender, EventArgs e)
{
// Enter save logic here...
}