If (_ exportdatatable! = NULL) // The memorystream to be saved {// create a save file dialog box Microsoft. win32.savefiledialog DLG = new Microsoft. win32.savefiledialog (); // Save the default file name DLG. filename = "History" + datetime. now. tostring ("yyyy-mm-dd hhmmss"); // default file format: DLG. defaultext = ". xls "; // filter and save the file in the format of DLG. filter = "History (.xls) | *. xls "; // record the last saved path DLG. restoredirectory = true; // The save file dialog box nullable <bool> result = DLG. showdialog (); // if you click OK, save the record if (result = true) {// Obtain the file path string localfilepath = DLG. filename. tostring (); string filenameext = localfilepath. substring (localfilepath. lastindexof ("\") + 1); // get the file path without the file name // memorystream savefilems = rendertoexcel (_ exportdatatable); filestream FS = new filestream (localfilepath, filemode. create); FS. write (savefilems. getbuffer (), 0, savefilems. getbuffer (). length) ;}} else {MessageBox. show ("no data! ");}