BKennedy2008
asked on
file upload to SharePoint Copy to a folder......
Can someone point or navigate me in SharePoint 2010 towards this task:
(I am assuming this is going to be a Workflow setting that is not Out of the Box...)
If a file is uploaded to a SharePoint 2010 document library, I need it to make a copy of the file into a folder on the Server...........not in SharePoint, but a folder that resides on the Server.
Sounds Easy, but with my Luck, it's probably not.....
(I am assuming this is going to be a Workflow setting that is not Out of the Box...)
If a file is uploaded to a SharePoint 2010 document library, I need it to make a copy of the file into a folder on the Server...........not in SharePoint, but a folder that resides on the Server.
Sounds Easy, but with my Luck, it's probably not.....
ASKER
I wnet down the road for FileSystemWatcher task, and it is not going to work. I have to move the file out of the system watch folder (SharePoint Document Library) which in my situation is not going to work for me.
I may have a 100 folders with 30 files in each, and I cannot be moving files out of the watched folder as they get copied to another folder.
I am leaning towards the event receiver. I know alot about VB.net code, but I have never have programmed in SharePoint. I think that is what I need to do, but I need to get steered in the right direction to do this. I am hoping to figure it out in hours and not days...
Thanks
I may have a 100 folders with 30 files in each, and I cannot be moving files out of the watched folder as they get copied to another folder.
I am leaning towards the event receiver. I know alot about VB.net code, but I have never have programmed in SharePoint. I think that is what I need to do, but I need to get steered in the right direction to do this. I am hoping to figure it out in hours and not days...
Thanks
Did you check my last comment in your other thread? Instead of just watching for files, watch for files that are newer than the last one your process copied.
Mike
Mike
ASKER
Yes, I did. As i thought about it, I think a more stable solution would be to program an event receiver to copy a file to the destination folder as it is created, updated, and deleted as in the case of the files contained in a Sharepoint Site are doing.
ASKER
Thanks Rainer, I have installed VS2010 on the SharePoint Server and created a new event receiver for files in a document library that look for a new file or an updated file, but looking where to go from here...Thanks
Option Explicit On
Option Strict On
Imports System
Imports System.Security.Permission s
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Secur ity
Imports Microsoft.SharePoint.Utili ties
Imports Microsoft.SharePoint.Workf low
Public Class EventReceiver1
Inherits SPItemEventReceiver
''' <summary>
''' An item was added.
''' </summary>
Public Overrides Sub ItemAdded(properties as SPItemEventProperties)
MyBase.ItemAdded(propertie s)
End Sub
''' <summary>
''' An item was updated.
''' </summary>
Public Overrides Sub ItemUpdated(properties as SPItemEventProperties)
MyBase.ItemUpdated(propert ies)
End Sub
End Class
Option Explicit On
Option Strict On
Imports System
Imports System.Security.Permission
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Secur
Imports Microsoft.SharePoint.Utili
Imports Microsoft.SharePoint.Workf
Public Class EventReceiver1
Inherits SPItemEventReceiver
''' <summary>
''' An item was added.
''' </summary>
Public Overrides Sub ItemAdded(properties as SPItemEventProperties)
MyBase.ItemAdded(propertie
End Sub
''' <summary>
''' An item was updated.
''' </summary>
Public Overrides Sub ItemUpdated(properties as SPItemEventProperties)
MyBase.ItemUpdated(propert
End Sub
End Class
ASKER
The following code is supposed to copy a file to a local folder once it is uploaded in SharePoint library, but its not working........
using System;
using System.IO;
using System.Text;
using System.Security.Permission s;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Secur ity;
using Microsoft.SharePoint.Utili ties;
using Microsoft.SharePoint.Workf low;
namespace EventReceiverProject2.Even tReceiver1
{
/// <summary>
/// List Item Events
/// </summary>
public class EventReceiver1 : SPItemEventReceiver
{
/// <summary>
/// An item is being added.
/// </summary>
public override void ItemAdding(SPItemEventProp erties properties)
{
StringBuilder strWFBuilderCheck = new StringBuilder();
strWFBuilderCheck.Append(@ "C:\TestFo lder\");
strWFBuilderCheck.Append(D ateTime.No w.Date.Yea r.ToString ());
strWFBuilderCheck.Append(D ateTime.No w.Date.Mon th.ToStrin g());
strWFBuilderCheck.Append(D ateTime.No w.Date.Day .ToString( ));
strWFBuilderCheck.Append(" _");
strWFBuilderCheck.Append(D ateTime.No w.TimeOfDa y.Hours.To String());
strWFBuilderCheck.Append(D ateTime.No w.TimeOfDa y.Minutes. ToString() );
strWFBuilderCheck.Append(D ateTime.No w.TimeOfDa y.Seconds. ToString() );
strWFBuilderCheck.Append(" _");
strWFBuilderCheck.Append(p roperties. ListItem.F ile.Name);
string WorkfFileLocationcheck;
WorkfFileLocationcheck = strWFBuilderCheck.ToString ();
BinaryWriter binWritercheck = new BinaryWriter(File.Open(Wor kfFileLoca tioncheck, FileMode.Create));
byte[] itembytescheck = properties.ListItem.File.O penBinary( );
string itemstringcheck = Encoding.ASCII.GetString(i tembytesch eck);
System.Text.ASCIIEncoding encodingcheck = new System.Text.ASCIIEncoding( );
byte[] bytescheck = encodingcheck.GetBytes(ite mstringche ck);
binWritercheck.Write(itemb ytescheck) ;
binWritercheck.Close();
}
}
}
using System;
using System.IO;
using System.Text;
using System.Security.Permission
using Microsoft.SharePoint;
using Microsoft.SharePoint.Secur
using Microsoft.SharePoint.Utili
using Microsoft.SharePoint.Workf
namespace EventReceiverProject2.Even
{
/// <summary>
/// List Item Events
/// </summary>
public class EventReceiver1 : SPItemEventReceiver
{
/// <summary>
/// An item is being added.
/// </summary>
public override void ItemAdding(SPItemEventProp
{
StringBuilder strWFBuilderCheck = new StringBuilder();
strWFBuilderCheck.Append(@
strWFBuilderCheck.Append(D
strWFBuilderCheck.Append(D
strWFBuilderCheck.Append(D
strWFBuilderCheck.Append("
strWFBuilderCheck.Append(D
strWFBuilderCheck.Append(D
strWFBuilderCheck.Append(D
strWFBuilderCheck.Append("
strWFBuilderCheck.Append(p
string WorkfFileLocationcheck;
WorkfFileLocationcheck = strWFBuilderCheck.ToString
BinaryWriter binWritercheck = new BinaryWriter(File.Open(Wor
byte[] itembytescheck = properties.ListItem.File.O
string itemstringcheck = Encoding.ASCII.GetString(i
System.Text.ASCIIEncoding encodingcheck = new System.Text.ASCIIEncoding(
byte[] bytescheck = encodingcheck.GetBytes(ite
binWritercheck.Write(itemb
binWritercheck.Close();
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, that was a mistake, but I set it to ItemsAdded instead of ItemsAdding, and no luck...
ASKER
Actually, the code above works fine when I set it to itemsadded....
I think you have to program either an event receiver to do this job or a custom coded workflow.
Perhaps an alternativ is to program a tool using FileSystemWatcher and bind that to a UNC mapped SharePoint document library.
HTH
Rainer