官方版
Build a Custom Importer or Exporter
Sample Extension
- Create a Fiddler extension project.
 - Modify the default class1.cs (or create a new class) in your project as follows: ```vbnet using System; using System.IO; using System.Text; using System.Windows.Forms; using Fiddler; using System.Diagnostics; using System.Reflection; [assembly: AssemblyVersion(“1.0.0.0”)] [assembly: Fiddler.RequiredVersion(“2.4.0.0”)]
 
[ProfferFormat(“TAB-Separated Values”, “Session List in Tab-Delimited Format”)] [ProfferFormat(“Comma-Separated Values”, “Session List in Comma-Delimited Format; import into Excel or other tools”)]
public class CSVTranscoder: ISessionExporter  // Ensure class is public, or Fiddler won’t see it!
{
  public bool ExportSessions(string sFormat, Session[] oSessions, Dictionary
// Determine if we already have a filename from the dictOptions collectionstring sFilename = null;if (null != dictOptions && dictOptions.ContainsKey("Filename")){sFilename = dictOptions["Filename"] as string;}if (sFormat == "Comma-Separated Values"){chSplit = ",";if (string.IsNullOrEmpty(sFilename)) sFilename = Fiddler.Utilities.ObtainSaveFilename("Export As " + sFormat, "CSV Files (*.csv)|*.csv");}else{chSplit = "\t";if (string.IsNullOrEmpty(sFilename)) sFilename = Fiddler.Utilities.ObtainSaveFilename("Export As " + sFormat, "TSV Files (*.tsv)|*.tsv");}if (String.IsNullOrEmpty(sFilename)) return false;try{StreamWriter swOutput = new StreamWriter(sFilename, false, Encoding.UTF8);int iCount = 0;int iMax = oSessions.Length;#region WriteColHeadersbool bFirstCol = true;foreach (ColumnHeader oLVCol in FiddlerApplication.UI.lvSessions.Columns){if (!bFirstCol){swOutput.Write(chSplit);}else{bFirstCol = false;}swOutput.Write(oLVCol.Text.Replace(chSplit, ""));}swOutput.WriteLine();#endregion WriteColHeaders#region WriteEachSessionforeach (Session oS in oSessions){iCount++;if (null != oS.ViewItem){bFirstCol = true;ListViewItem oLVI = (oS.ViewItem as ListViewItem);if (null == oLVI) continue;foreach (ListViewItem.ListViewSubItem oLVC in oLVI.SubItems){if (!bFirstCol){swOutput.Write(chSplit);}else{bFirstCol = false;}swOutput.Write(oLVC.Text.Replace(chSplit, ""));}swOutput.WriteLine();}if (null != evtProgressNotifications){evtProgressNotifications(null, new ProgressCallbackEventArgs(, ));ProgressCallbackEventArgs PCEA = new ProgressCallbackEventArgs((iCount/(float)iMax), "wrote " + iCount.ToString() + " records.");evtProgressNotifications(null, PCEA);if (PCEA.Cancel) { swOutput.Close(); return false; }}}#endregion WriteEachSessionswOutput.Close();bResult = true;}catch (Exception eX){MessageBox.Show(eX.Message, "Failed to export");bResult = false;}
} return bResult; }
public void Dispose() { } }
1. [Compile and load your extension in Fiddler](https://docs.telerik.com/fiddler/Extend-Fiddler/LoadExtension).<br /><a name="see-also"></a>## [See Also](https://docs.telerik.com/fiddler/Extend-Fiddler/BuildImporterExporter#see-also)[Build extension assemblies to run in both Fiddler 2 and 4](https://docs.telerik.com/fiddler/Extend-Fiddler/ExtensionsForv2Andv4)<a name="t44ST"></a># 谷歌翻译版<a name="8vbkx"></a># [建立自定义导入或者导出](https://docs.telerik.com/fiddler/Extend-Fiddler/BuildImporterExporter#build-a-custom-importer-or-exporter)<a name="md8WD"></a>## [示列扩展](https://docs.telerik.com/fiddler/Extend-Fiddler/BuildImporterExporter#sample-extension)1. 创建一个 [Fiddler 扩展项目](https://docs.telerik.com/fiddler/Extend-Fiddler/CreateExtension).1. 在项目中修改默认的class1.cs(或创建一个新类),如下所示:```vbnetusing System;using System.IO;using System.Text;using System.Windows.Forms;using Fiddler;using System.Diagnostics;using System.Reflection;[assembly: AssemblyVersion("1.0.0.0")][assembly: Fiddler.RequiredVersion("2.4.0.0")][ProfferFormat("TAB-Separated Values", "Session List in Tab-Delimited Format")][ProfferFormat("Comma-Separated Values","Session List in Comma-Delimited Format; import into Excel or other tools")]public class CSVTranscoder: ISessionExporter // Ensure class is public, or Fiddler won't see it!{public bool ExportSessions(string sFormat, Session[] oSessions, Dictionary<string, object> dictOptions,EventHandler<ProgressCallbackEventArgs> evtProgressNotifications){bool bResult = false;string chSplit;// Determine if we already have a filename from the dictOptions collectionstring sFilename = null;if (null != dictOptions && dictOptions.ContainsKey("Filename")){sFilename = dictOptions["Filename"] as string;}if (sFormat == "Comma-Separated Values"){chSplit = ",";if (string.IsNullOrEmpty(sFilename)) sFilename = Fiddler.Utilities.ObtainSaveFilename("Export As " + sFormat, "CSV Files (*.csv)|*.csv");}else{chSplit = "\t";if (string.IsNullOrEmpty(sFilename)) sFilename = Fiddler.Utilities.ObtainSaveFilename("Export As " + sFormat, "TSV Files (*.tsv)|*.tsv");}if (String.IsNullOrEmpty(sFilename)) return false;try{StreamWriter swOutput = new StreamWriter(sFilename, false, Encoding.UTF8);int iCount = 0;int iMax = oSessions.Length;#region WriteColHeadersbool bFirstCol = true;foreach (ColumnHeader oLVCol in FiddlerApplication.UI.lvSessions.Columns){if (!bFirstCol){swOutput.Write(chSplit);}else{bFirstCol = false;}swOutput.Write(oLVCol.Text.Replace(chSplit, ""));}swOutput.WriteLine();#endregion WriteColHeaders#region WriteEachSessionforeach (Session oS in oSessions){iCount++;if (null != oS.ViewItem){bFirstCol = true;ListViewItem oLVI = (oS.ViewItem as ListViewItem);if (null == oLVI) continue;foreach (ListViewItem.ListViewSubItem oLVC in oLVI.SubItems){if (!bFirstCol){swOutput.Write(chSplit);}else{bFirstCol = false;}swOutput.Write(oLVC.Text.Replace(chSplit, ""));}swOutput.WriteLine();}if (null != evtProgressNotifications){evtProgressNotifications(null, new ProgressCallbackEventArgs(, ));ProgressCallbackEventArgs PCEA = new ProgressCallbackEventArgs((iCount/(float)iMax), "wrote " + iCount.ToString() + " records.");evtProgressNotifications(null, PCEA);if (PCEA.Cancel) { swOutput.Close(); return false; }}}#endregion WriteEachSessionswOutput.Close();bResult = true;}catch (Exception eX){MessageBox.Show(eX.Message, "Failed to export");bResult = false;}}return bResult;}public void Dispose(){}}
