To prompt the user with a "Save As" file prompt:
Create a button on your form. Set the Click event to btnSaveAsClick().
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnSaveAs_Click(Object sender, EventArgs e)
{
String path = GetSaveFileName("usage.csv");
if(String.IsNullOrEmpty(path)) return;
//Write your file here using 'path'
}
private String GetSaveFileName(String SuggestedFileName)
{
SaveFileDialog ofd = new SaveFileDialog();
ofd.FileName = SuggestedFileName;
ofd.DefaultExt = "csv";
ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
return ofd.ShowDialog()==DialogResult.OK ? ofd.FileName : "";
}
}
Please remember to click the green checkmark if this solves your issue.