I have created event receiver (Item added) which is attached to document library. Whenever document is added/uploaded in document library which should create copy of it on file system.Following is my code.
public override void ItemAdded(SPItemEventProperties properties)
{
try
{
SPSecurity.RunWithElevatedPrivileges(delegate ()
{
using (SPSite site = properties.OpenSite())
{
using (SPWeb web = site.OpenWeb())
{
SPFile file = properties.ListItem.File;
FileStream stream = new FileStream("E:\\DownloadedImages\\" + file.Name, FileMode.Create);
//Error on above line
BinaryWriter writer = new BinaryWriter(stream);
writer.Write(file.OpenBinary());
writer.Close();
}
}
});
}
catch (Exception ex)
{
}
base.ItemAdded(properties);
}
I am getting following error on mentioned line.
An exception of type 'System.NotSupportedException' occurred in mscorlib.dll but was not handled in user code Additional information: The given path's format is not supported.