deny hilman

deny hilman

  • NA
  • 3
  • 4.7k

move file

Nov 21 2013 10:50 PM
hi all

i making a move script for move library file to another library site, but i get error
this my code

using (SPSite sourceSite = new SPSite("http://intranet.semenpadang.co.id/pusm/Biro PSPI"))
                {
                    
                    using (SPWeb sourceWeb = sourceSite.OpenWeb())
                    {
                        
                        SPList sourceList = sourceWeb.Lists["Dokumen PSPI"];
                        SPListItem item = sourceList.GetItemById(2);
                        //SPListItem item = sourceList.GetItemById(24);

                        using (SPSite destSite = new SPSite("http://project.semenpadang.co.id/capex/Cement Mill Dumai"))
                        {
                            sourceSite.AllowUnsafeUpdates = true;
                            using (SPWeb destWeb = destSite.OpenWeb())
                            {
                                sourceWeb.AllowUnsafeUpdates = true;
                                SPFolder destFolder = destWeb.Folders["Surat Masuk"];
                                destWeb.AllowUnsafeUpdates = true;
                                destFolder.Files.Add(item.File.Name, item.File.OpenBinary(), true);
                                //myItem["Nomor Gambar/Dokumen"] = 
                                destFolder.Update();

                            }
                        }
                    }
                }

and this the error, please help me all, thank

System.UnauthorizedAccessException was unhandled by user code
  Message=<nativehr>0x80070005</nativehr><nativestack></nativestack>Access denied.
  Source=""
  StackTrace:
       at Microsoft.SharePoint.SPGlobal.HandleUnauthorizedAccessException(UnauthorizedAccessException ex)
       at Microsoft.SharePoint.Library.SPRequest.PutFile(String bstrUrl, String bstrWebRelativeUrl, Object punkFile, Int32 cbFile, Object punkFFM, PutFileOpt PutFileOpt, String bstrCreatedBy, String bstrModifiedBy, Int32 iCreatedByID, Int32 iModifiedByID, Object varTimeCreated, Object varTimeLastModified, Object varProperties, String bstrCheckinComment, Byte partitionToCheck, Int64 fragmentIdToCheck, String bstrCsvPartitionsToDelete, String bstrLockIdMatch, String bstEtagToMatch, Int32 lockType, String lockId, Int32 minutes, Int32 fRefreshLock, Int32 bValidateReqFields, Guid gNewDocId, UInt32& pdwVirusCheckStatus, String& pVirusCheckMessage, String& pEtagReturn, Byte& piLevel, Int32& pbIgnoredReqProps)
       at Microsoft.SharePoint.SPFileCollection.AddStreamOrBytesInternal(String urlOfFile, Stream file, PutFileOpt fileOpt, String createdBy, String modifiedBy, Int32 createdByID, Int32 modifiedByID, DateTime timeCreated, DateTime timeLastModified, Object varProperties, String checkInComment, Stream formatMetadata, String lockIdMatch, String etagToMatch, SPLockType lockType, String lockId, TimeSpan lockTimeout, Boolean validateRequiredFields, SPVirusCheckStatus& virusCheckStatus, String& virusCheckMessage, String& etagNew, Boolean& ignoredRequiredProps)
       at Microsoft.SharePoint.SPFileCollection.Add(String urlOfFile, Byte[] file, Boolean overwrite, String checkInComment, Boolean checkRequiredFields)
       at Microsoft.SharePoint.SPFileCollection.Add(String urlOfFile, Byte[] file, Boolean overwrite)
       at move.Workflow1.Workflow1.moving(Object sender, EventArgs e)
       at System.Workflow.ComponentModel.Activity.RaiseEvent(DependencyProperty dependencyEvent, Object sender, EventArgs e)
       at System.Workflow.Activities.CodeActivity.Execute(ActivityExecutionContext executionContext)
       at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(T activity, ActivityExecutionContext executionContext)
  InnerException: 

Answers (1)