Hi,
I'm still trying to learn a little C#.
I wanted to make a LISP function as getfiled but wich allows multiple selection using the Windows OpenFileDialog.
It works fine at home (XP & A2007), and I uploaded it on a French website to have some different release tests.
I had good returns excepted one who had an error :
_.netload Nom du fichier d'assemblage: GetFileLisp.dll
Commande: Échec de la demande d'autorisation de type
'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089'.
I tried to had some permission but cannot get it work with this guy.
using System.Windows.Forms;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using System.Security.Permissions;
namespace GetFileLisp
{
public class myClass
{
/*
* Fonction LISP getfiles
* Ouvre une boite de dialogue permettant de choisir un ou plusieurs fichier
* (getfiles repertoire filtre [multiple])
*Exemple :
* (getfiles "C:\\" "Dessin (*.dwg)|*.dwg|Tous (*.*)|*.*" T)
*/
[LispFunction("getfiles")]
public static ResultBuffer GetFileDialog(ResultBuffer buff)
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
ResultBuffer result = new ResultBuffer();
try
{
if (buff == null)
{
ed.WriteMessage("Erreur: nombre d'arguments insuffisants\n");
return null;
}
TypedValue[] args = buff.AsArray();
if (args.Length < 2)
{
ed.WriteMessage("Erreur: nombre d'arguments insuffisants\n");
return null;
}
if (args.Length > 3)
{
ed.WriteMessage("Erreur: nombre d'arguments trop important\n");
return null;
}
if (args[0].TypeCode != (int)LispDataType.Text)
{
ed.WriteMessage("Erreur: type d'argument incorrect: stringp {0}\n", args[0].Value);
return null;
}
if (args[1].TypeCode != (int)LispDataType.Text)
{
ed.WriteMessage("Erreur: type d'argument incorrect: stringp {0}\n", args[1].Value);
return null;
}
bool mult = ((args.Length == 3) && (args[2].TypeCode != (int)LispDataType.Nil)) ? true : false;
[color=#FF6600]//This was added to try get it work, but doesn't
FileIOPermission permission = new FileIOPermission(PermissionState.None);
permission.AllFiles = FileIOPermissionAccess.PathDiscovery; [/color]
OpenFileDialog openDialog = new OpenFileDialog();
openDialog.InitialDirectory = (string)args[0].Value;
openDialog.Filter = (string)args[1].Value;
openDialog.FilterIndex = 1;
openDialog.Multiselect = mult;
if (openDialog.ShowDialog() == DialogResult.OK)
{
if (mult)
{
string[] fileNames = openDialog.FileNames;
foreach (string file in fileNames)
{
result.Add(new TypedValue((int)LispDataType.Text, file));
}
}
else
{
string file = openDialog.FileName;
result.Add(new TypedValue((int)LispDataType.Text, file));
}
return result;
}
else return null;
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.Message + "\n");
return null;
}
}
}
}
Here's the
GetFileLisp.dll