Email Most Recent File From Directory

I am using C# to open a Spreadsheet, change 3 things in the spreadsheet, then save the spreadsheet in a directory, then open the directory.  I was trying to use FileSystemWatcher to capture the most recent file in the directory, but it seems that the
Watch() event is being triggered before my syntax is able to make the changes and save.
Is their a better method for this or do I just need to add in a Thread.Sleep() event so that the Watch() event triggers after the save is complete?

Hi Indigo,
>>I was trying to use FileSystemWatcher to capture the most recent file in the directory,
but it seems that the Watch() event is being triggered before my syntax is able to make the changes and save.
I have tested your code on my side, I supposed that you can add one button, when you
change and save xls file successfully, try to trigger Watch() event by manual.
I changed a little code with yours.
Watch for changes in LastAccess and LastWrite times, and  the renaming of files or directories.
Add all event handlers.
Use messageBox to show something instead
Here is my test reslut:
 Do I miss something? If so, please feel free to post here.
public partial class Form1 : Form
public Form1()
InitializeComponent();
filewatcher();
private void filewatcher()
using (Process pRun = new Process())
pRun.StartInfo.FileName = "D:\\Test\\test.xlsx";
pRun.StartInfo.UseShellExecute = true;
pRun.Start();
string openPath = "D:\\Test\\";
Process pRC = new Process();
pRC.StartInfo.FileName = openPath;
pRC.Start();
private void Watch()
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = "D:\\Test";
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
watcher.Filter = "*.xlsx";
// Add event handlers.
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.EnableRaisingEvents = true;
private void OnChanged(object source, FileSystemEventArgs e)
WatcherChangeTypes changeTypes = e.ChangeType;
String filename = e.Name.ToString();
MessageBox.Show("Hello");
private void button1_Click(object sender, EventArgs e)
Watch();
MessageBox.Show("DOne");
//private void sendMail(string filename)
// using (MailMessage mail = new MailMessage())
// mail.From = new MailAddress("");
// mail.To.Add("");
// string fileDirectory = path;
// string fileFullPath = Path.Combine(filesDirectory, filename);
// if (!File.Exists(fileFullPath))
// return;
// using (var xlsx1 = new Attachment(fileFullPath))
// mail.Subject = "Test";
// mail.Attachments.Add(xlsx1);
// SmtpClient client = new SmtpClient("SMTP.MAIL.COM");
// client.Send(mail);
Best Regards,
Kristin
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.

Similar Messages

  • Finding most recent file in a directory

    Hi,
    Is there a simple and easy way in labview to write a program that goes
    into a directory and looks for the most recent file. I can think of one
    way where I use the list directory vi to obtain an array of the file
    names in the directory and then use the file/directory info vi to
    obtain a time stamp for each file in the directory and afterwards sort
    all the time stamps. I'm not sure if this is the simplest way to do
    this, and wanted to ask if anyone on the discussion forums knows of any.
    Thank you

    unclebump wrote:
    Try here. http://zone.ni.com/devzone/cda/epd/p/id/3175
    This example is not that great and a few tweaks can greatly improve it!
    Building the path with string operations inside the loop automatically breaks this VI on anything but windows. There is a reason we have the "build path" function! It should always be used. The "string to path" and "path to string" should only be used for OS specific tasks.
    You probably want to skip files that are actually links. Newer versions of "File/Directory info" tell you if the path points to a link instead of a file with a boolean output.
    WIy do we need to keep an array of all files and maintain the corret index in a shift register. It seems more intuitive and less wasteful to just keep the newest file path in the shift register and not worry about the index.
    The image below shows a quick attempt at improving the example. Modify as needed.
    Message Edited by altenbach on 04-12-2007 02:45 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    find_newest_real_file.png ‏9 KB

  • Cannot see most recent files when attaching

    I've had this problem for a while. Currently using OS X Mavericks, 10.9.4 (latest version) and Mail 7.3 (also latest build).  Saved a file to Documents, then opened Mail and attempted to attach it. Finder window opens, but my most recent files viewed are "last 7 days," with "today" being completely missing. I can open the Finder independently, the files show, I can open the files, send the file as an attachment from the Finder itself. But for quite some time, I don't see my most recent files (like today's files) in Finder when first opening Mail and attempting to attach something from a new message or message reply. Very frustrating.
    Anyone know what's going on here? I've experienced this before, but this is the first I realized that it seems as if it only happens when I am searching for a file to attach, and not when I open the Finder directly. I know there are workarounds, but I would just like to be able to do this simple thing, and for the life of me, I cannot do it. Not sure how long this has been going on, but I think it was happening in Mavericks all along, I just didn't connect the dots.
    Thanks.

    I can't duplicate the issue. What type of file is it? Is it saved locally, in the cloud, external drive?

  • When I sort by date added in Column View in Finder, how can I make the most recent files appear at the top of the list?(Mavericks)

    In 10.8, when I sorted Finder by date added or date created in column view, the most recent files would appear at the top of the list. Currently, this happens as it should in every single view mode EXCEPT column view (which is pretty much the only view I ever use). Currently, I have a folder with over 2000 files in it that date back to 2011, so now I have to scroll for like ten minutes just te get to files that were most recently added. Who in their right mind would want to sort by last modified with the oldest result listed FIRST? Ridiculous. I can't figure this out. Any help?

    Thanks for the reply leroydouglas! Unfurtunately this doesn't cause the column to be ordered correctly either. After selecting this option, the files seem to be ordered by label, and the most recently added file is somewhere in the middle of the list. I'd like it to be at the top, and have other files/folders descend in retrochronological order by their add date.
    Any other input from the community would be greatly appreciated, even if it's just confirming that this is/is not expected behavior. I'd be super bummed to find out that this IS expected behavior, as it's really counterintuitive and extremely inconvenient.
    Thanks again!

  • Not Showing Most Recent Files

    I've got a strange one. I've been able to network my imac to a dell laptop and they can see each other's shared directories. Tried to access an Excel file from the laptop and it didn't show the most recent file, but one that was nearly three weeks old. Is the imac caching the files anywhere? I didn't see any windows settings. Still getting used to the Mac world and didn't see any ability to refresh. Any ideas would be appreciated. Thanks in advance.

    Any pattern? Are they the most recently created or modified? Anything in common about how they are named, or in the +dot plus three+ extensions? Are you still seeing the older version of files on the Mac compared to directly in Windows.
    I've not used Windows 7 so I'm not familiar with any sharing filters that are possible. If you are still seeing older versions of files, and the ones you don't see on the Mac happen to be the most recently added to the folder, it still feels to me like you are actually connecting to a different sharepoint than what you believe... maybe one that is in an backup archive or something.
    Sorry I can't be any more helpful. It's a bit mysterious.

  • How to delete a READ ONLY file from Directory

    Hi Friends,
    how to delete a READ ONLY file from Directory , file is in my system only.
    Please help me .
    note: its read only file.
    Thank you.
    Karthik.

    hI,
    try with this statement.
    delete dataset <datasetname>.
    this will definitely work.
    Regards,
    Nagaraj

  • Read file from directory, update contents of the each file

    hai,
    I could not understand how to debug the error i have now.
    target
    1- read the files from directory // i able ot do this part
    2- for each file
    for each file read the content & compare with the existing List & update the list // i able to do this part
    when i try to combine both parts , i got some following error
    run:
    E:\java\check\100130.ixf
    Error: children[i] (The system cannot find the file specified)
    BUILD SUCCESSFUL (total time: 2 seconds)
    i can see from the code that children[i] only gives the error when i use that in the second part of the code.
    can any one help me on this??
    Thanks
    Priyan
    the original code
    import java.io.BufferedReader;
    import java.io.DataInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.InputStreamReader;
    import java.io.RandomAccessFile;
    import java.util.ArrayList;
    public class CompareList
         public static void main(String[] args){
             ArrayList a1 = new ArrayList();
             ArrayList a2 = new ArrayList();
             a1.add("1");
             a1.add("2");
             a1.add("3");
             a1.add("4");
             a1.add("5");
             a1.add("6");
             a1.add("7");
             a1.add("8");
             a1.add("9");
             a1.add("10");
             a1.add("11");
             a1.add("12");
             a1.add("13");
             a1.add("14");
             a1.add("15");
             a1.add("16");
             a1.add("17");
             a1.add("18");
             a1.add("19");
             a1.add("20");
             a1.add("21");
             a1.add("22");
             a1.add("23");
             a1.add("24");
             a1.add("25");
             a1.add("26");
             a1.add("27");
             a1.add("28");
             a1.add("29");
             a1.add("30");
             a1.add("31");
             a1.add("32");
             a1.add("33");
             a1.add("34");
             a1.add("35");
             a1.add("36");
             a1.add("37");
             a1.add("38");
             a1.add("39");
             a1.add("40");
             a1.add("41");
             a1.add("42");
             a1.add("43");
             a1.add("44");
             a1.add("45");
             a1.add("46");
             a1.add("47");
             a1.add("48");
             a1.add("49");
             a1.add("50");
             a1.add("51");
             a1.add("52");
              try{
                    File dir = new File("E:\\java\\check");
                    File[] children = dir.listFiles();
                    if (children == null) {
                          System.out.println("does not exist or is not a directory");
        else {
               for (int i = 0; i < children.length; i++) {
                       System.out.println( children);
    FileInputStream fstream = new FileInputStream("children[i]");
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;
    while ((strLine = br.readLine()) != null)      {
    String line =strLine.substring(0,2);
    // Print the content on the console
    //System.out.println(line);
    a2.add(line);
    } // end of add list2
    if (a1.size() > a2.size())
    int k = 0;
    for (int l = 0; l < a2.size(); l++)
    if (!((String)a1.get(l)).equals((String)a2.get(l)))
    //System.out.println((String)a2.get(i));
    // System.out.println("dd");
    k = l;
    k++;
    for (int l = k; l < a1.size(); l++)
    System.out.println((String)a1.get(l));
    String str = "children[l]";
    File file = new File(str);
    RandomAccessFile rand = new RandomAccessFile(file,"rw");
    rand.seek(file.length()); //Seek to end of file
    rand.writeBytes((String)a1.get(i)); //Write end of file
    rand.writeBytes("., 0.");
    rand.writeBytes("\n");
    }// end of comparing and updating the list2
              in.close();
    catch (Exception e){//Catch exception if any
    System.err.println("Error: " + e.getMessage());

    thanks for the information.
    i tried, the error
    like this
    run:
    E:\java\check\100130.ixf
    java.lang.StringIndexOutOfBoundsException: String index out of range: 2
            at java.lang.String.substring(String.java:1935) 
            at CompareList.main(CompareList.java:84)
    BUILD SUCCESSFUL (total time: 0 seconds)this comes because in my code i used children[i] as string in the later part
        else {
               for (int i = 0; i < children.length; i++) {
                        System.out.println( children);
    FileInputStream fstream = new FileInputStream(children[i]);
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;
    while ((strLine = br.readLine()) != null)      {
    String line =strLine.substring(0,2);
    a2.add(line);
    System.out.println(line);
    } // end of add list2
    if (a1.size() > a2.size())
    int k = 0;
    for (int l = 0; l < a2.size(); l++)
    if (!((String)a1.get(l)).equals((String)a2.get(l)))
    //System.out.println((String)a2.get(i));
    // System.out.println("dd");
    k = l;
    k++;
    for (int l = k; l < a1.size(); l++)
    System.out.println((String)a1.get(l));
    String str = "children[l]";
    File file = new File(str);
    RandomAccessFile rand = new RandomAccessFile(file,"rw");
    rand.seek(file.length()); //Seek to end of file
    rand.writeBytes((String)a1.get(i)); //Write end of file
    rand.writeBytes("., 0.");
    rand.writeBytes("\n");
    rand.close();
    }// end of comparing and updating the list2
              in.close();
    i stil could not figure out it yet. do u have any clue with this.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Why can't I email a pdf file from Acrobat XI Standard?

    Whenever I try to email a pdf file from Acrobat XI Standard, nothing happens. Outlook 2007 is my default
    email program. I have checked the preferences to be sure that Outlook is checked as default, and it is,
    but when I click on the email icon or select email from the dropdown menu, nothing happens. This is
    so frustrating. I hope someone can help me solve this problem.

    Be sure that MAPI is properly active in your Outlook. I am not an Outlook user, but that is what is needed.

  • I'm using iphone 4S, and I can not open PDF file only from my husband email that using Mic outlook. It was very weird because I can received other email with pdf file from other people. can someone help.

    I'm using iphone 4S and ipad mini, and I can not open PDF file only from my husband email that using Mic outlook. It was very weird because I can received other email with pdf file from other people. Can someone help...
    Thanks in advance

    Hi Eidda,
    This may because the attachment is a winmail.dat file. I would recommend taking a look at the article below for more information. Note: the article is written for OS X mail, but does also apply to this situation.
    Mac OS X Mail: What is a winmail.dat attachment?
    http://support.apple.com/kb/HT2614
    -Griff W.

  • Let Photoshop automatically load the most recent file

    I have in the task bar icons for the PostScript editor PSAlter and for Photoshop.
    The workflow is always: Edit in PSAlter and interpret in Photoshop.
    Clicking in the task bar on the Photoshop icon should open Photoshop, load
    the most recent file (which is meanwhile modified), confirm last settings by OK
    and start the execution.
    Is it possible to automate this sequence – by just one click on the icon?
    Best regards --Gernot Hoffmann

    I doubt that would work out well.
    One could possibly link a Script to Photoshop being "brought to the foreground" with Script Events Manager but that might not always be the intended process when switching to Photoshop.
    How exactly is the "most recent file" identifiable?
    Do you change the settings often or could they stay fixed?
    Maybe you should also ask over at
    Photoshop Scripting

  • How to save my emails and adressbook files from an old ibook?

    How to save my emails and adressbook files from an old ibook (bought around 2002) ?
    The screen from the old ibook doesn´t work anymore (logicboard problem I guess).
    I saved everything else with starting it in target modus. That worked fine.
    I want to delete the files after that as well, because I wanna give away the old ibook and don´t want anyone to read my emails!
    Little helpers I have:
    A running MacBook
    External Screen (and cables to connect)
    Fire Wire Cable

    Don't know how helpful this will be but I often copy mail from one computer to another, I drag the mail from the mail window to the other computers drop box, then from the other computer double click it and mail asks me what I want to do with it, of course without a screen you'd need to use back to my mac.
    If you don't have back to my mac running, you could set up a second user account on the newer mac, import everything via target mode as suggested by c above, and then drag the mail to the first user account drop box.

  • HOW TO READ MULTIPLE FILES FROM DIRECTORY

    i have a directory with 100 .sql insert scripts.i want to read all .sql files from directory and execute the insert script automatically.

    Let's suppose you have 3 files: "first.sql", "second.sql" and "third.sql". Create a file named "all.sql" in the same directory, containing this:
    @@first.sql
    @@second.sql
    @@third.sqlRun "all.sql".

  • Hi to all, I use Windows 7, 64Bit and Lightroom 5.7, Camera Raw 8.7, when I develop or export files (mostly Raw Fils from Nikon D810) after 10 to 20 pictures my computer shuts down or I get a bluescreen. Please tell me why.

    Hi to all, I use Windows 7, 64Bit and Lightroom 5.7, Camera Raw 8.7, when I develop or export files (mostly Raw Fils from Nikon D810) after 10 to 20 pictures my computer shuts down or I get a bluescreen. Please tell me why.

    Blue screen/Computer shuts down is almost always a hardware malfunction or a driver problem.
    Make sure your video driver is up to date.
    If it is, then the next suspect, in my mind, is overheating, make sure all of the fans in your CPU case are working properly.

  • How do I transfer my email history and files from windows using MS Outlook to an imac

    I am about to buy an iMac.  How do I transfer my email history and files from my MS Windows based computer, using Outlook?

    You might want to use Migration assistant. On the internet you will find the Windows software to install on your Windows computer.
    Mac has its own assistant, called configuration assistant.
    On the Windows PC, you will need to shutdown antivirus software and also to turn-off the Windows Firewall.
    After software installation and starting the program on your Windows PC, you need to run configuration assistant on your mac.
    Best and fastest sollution would be to connect both computers with a UTP cable.
    Follow instructions to be found here:
    Switch Basics: Migrate your Windows files to your Mac
    Hope it works out for you.
    Goodluck

  • Full restore from Time Machine - how do I get most recent files back???

    Hi all,
    I've had some major problems with my hard-disk today (Disk Utility complaining about all sorts of things and not being able to repair them) so I thought I'll just wipe my disk and restore from back-up.
    But: when I was asked to choose a backup the most recent one was from 7th November. It said that only full backups are shown (and incremental backups are not shown...). Well, since I had no choice anymore, I selected the most recent one and hoped I could get things back again later. But I'm now struggling to find a decent way of doing this:
    All the more recent versions are on the time machine disk - I can see the files in the different folders. But in Time Machine itself, I cannot select any of the back-ups from between 7th November and now - they are shown to exist, but they are greyed out.
    Is there any way to return to my most recent state other than restoring the whole thing one-by-one from dozens of different folders?
    Any help would be greatly appreciated
    Thanks in advance!
    Sebastian

    Sebastian Hoffmann wrote:
    But: when I was asked to choose a backup the most recent one was from 7th November. It said that only full backups are shown (and incremental backups are not shown...).
    No, incomplete backups are not shown, including backups that failed, were cancelled, or were made with System files excluded. Other than that, all TM backups are, in effect, full ones.
    All the more recent versions are on the time machine disk - I can see the files in the different folders. But in Time Machine itself, I cannot select any of the back-ups from between 7th November and now - they are shown to exist, but they are greyed out.
    Is there any way to return to my most recent state other than restoring the whole thing one-by-one from dozens of different folders?
    Could you have renamed your internal HD on or about November 7? That's one possible explanation for what you're seeing. If so, TM would treat it as a separate disk: there would have been two disks listed in the pop-up menu above the list of available backups (item e. in the green box in #14 of the Frequently Asked Questions *User Tip* at the top of this forum).
    If that's a possibility, boot up from your SL Install disc again, and go through the process that far. If you find two disk names listed there, select the other one and see what dates are available. If you find your recent backups, do the restore again from one of them.
    If not, reboot normally, then try the +*Browse . . .+* Option, per #17 in the Frequently Asked Questions *User Tip* at the top of this forum.
    Restore what you need from the latest backup you can find that way. That will get the most recent version of everything. You can't restore your home folder that way, but you can restore each sub-folder and it's contents that way.

Maybe you are looking for

  • [JS] Move Page position in CS3/CS4? (like CS5's page.transform)

    When resizing a document, by default InDesign uses a center reference point. In CS5 and later I know I can use page.transform to move the page's position to where I want it (the art does not move, the page underneath the art). Is there anyway to do t

  • Error in integration Log not found (in main memory)

    Hello Experts, We are facing an error at the moment  when we send a contract from CLM to the ERP, we run the transaction BBP_ES_ANALYZE and the error that we got is Log not found (in main memory). We already reviewed all master data integration, any

  • Older programs

    Hi Guys, I have an older mac mini g4, running panther, and have just upgraded to my new 8 core mac pro, running leopard. There were a few nice apps that came with the mini on the bundled recovery discs - games the family likes. I would like to be abl

  • If I buy an iPhone 4S (the unlocked and contract-free version), do I need to add a microSIM card if I just want to use it as an iPod Touch?

    If I buy an iPhone 4S (the unlocked and contract-free version), do I need to add a microSIM card if I just want to use it as, essentially, an iPod Touch? I'll probably get a microSIM card eventually, but I just need the wi-fi based technology now. An

  • Image shifting back and forth

    Is anyone experiencing strange shifts back and forth of images while they are working with them? The image moves about 1mm diagonally, sometimes a couple of times. Also scrolling of galleries seems to be much less smooth than before, sometimes lockin