Control
add-ins for the Microsoft Dynamics NAV are built with the Microsoft .NET
Framework–based assemblies that you install on computers that are running the
Microsoft Dynamics NAV Windows client.
To
include a control add-in on a Role Center, you apply the control add-in on a
page that is assigned to a part of the Role Center. Control add-ins are not
supported by the Microsoft Dynamics NAV Web client or Microsoft Dynamics NAV
Portal Framework for Microsoft SharePoint 2010
Here we will see an example of Drag and Drop a file in the
text box controls. On drag and drop the text box will provide you the path of
the file with the filename and extension.
Follow the below procedure for Drag and Drop a file:
1.
Open Visual Studio.2. Select C# class library and provide the name for the solution. Here we have given name as DragDrop.
3. A New Class file will open.
4. Add the following references:
- System.Drawing
- System.Windows.Forms
- Microsoft.Dynamics.Framework.UI.Extensibilty.dll, by default, it is available in Program Files\Microsoft Dynamics NAV\60\RoleTailored Client folder.
using
System.Drawing;
using
System.Windows.Forms;
using
Microsoft.Dynamics.Framework.UI.Extensibility;
using
Microsoft.Dynamics.Framework.UI.Extensibility.WinForms;
using
System.IO;
namespace
DragDrop
{
[ControlAddInExport
("DragandDrop3.5")]public class DraGDroP:WinFormsControlAddInBase
{
TextBox
txt;
protected
override Control
CreateControl()
{
txt = new
TextBox();
txt.MinimumSize = new Size(50, 0);
txt.MaximumSize = new Size(500, Int32.MaxValue);
txt.DragEnter += new DragEventHandler(txt_DragEnter);
txt.DragDrop += new DragEventHandler(txt_DragDrop);
txt.AllowDrop = true;
return
txt;
throw
new NotImplementedException();
}
private
void txt_DragEnter(Object
Sender, DragEventArgs e)
{
if(e.Data.GetDataPresent(DataFormats.FileDrop,false))
{
e.Effect =DragDropEffects.All;
}
}
private
void txt_DragDrop(Object
sender, DragEventArgs e)
{
try
{
int
index = 0;
string
data;
string[]
filecollection =(string[])e.Data.GetData(DataFormats.FileDrop );
foreach
(string file in
filecollection )
{
//this.txt.Text
= Path.GetFileName (file);
this.txt.Text
= Path.GetFullPath(file);
}
data=this.txt.Text;
}
catch
(Exception ex)
{
}
}
}
}
7. Go to Project propertiesàsigning.
8. Select the checkbox “Sign the assembly”. Now choose a String Name key.
9. Click New. Specify the name and protect your assembly with Password.
10. Save and Build the Solution.
11. Copy the assembly dll from the folder you have saved. By Default, C:\My Documents\Visual Studio\Projects\[Addin Project name]\bin\Debug.
12. Paste the dll in the Add-Ins folder of the Role Tailored client. By default, C:\Program Files\Microsoft Dynamics NAV\60\RoleTailored Client\Add-ins.
13. Now we need to create a Public Key token.
14. Follow the link for creating public key token. http://msdn.microsoft.com/en-in/library/dd983825.aspx
15. Copy the Public key token created.
16. Now Open table Client add-in(2000000069) in Dynamics NAV.
17. Type the Control Add-in name as “DragandDrop3.5”.
18. Paste the copied Public Key.
19. Now Exit from the table.
20. Create a New Page in Page Designer. Like Below image.
21.
Go
to the Control Add –in Property of a Field “Drag a File and Drop” and Choose
the Public key token that created for this add-in.
22.
Save,
Compile and Run the Page.
23.
Now
drag a file from any of your folder and place in the text box.
24.
Refer
the below image
No comments:
Post a Comment