Results 1 to 9 of 9

Thread: Copy paste error

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    5

    Copy paste error

    Hi,

    I'm trying to copy a picture from one location and paste it into another location however VB throws out the following error

    Exception from HRESULT: 0x800A0046 (CTL_E_PERMISSIONDENIED)

    both locations are on my local computer. So not sure what is causing the problem.

    Here's the code



    Module CPASU_SPC

    Sub Main()
    Console.Title = "MOARW Programs"
    Console.WriteLine("Begin Application" & vbLf)
    Console.Beep()
    Console.ReadLine()
    Dim objFSO
    Dim CPASU_Journal, vSharePoint, fsoSource, fsoDest
    objFSO = CreateObject("Scripting.FileSystemObject")
    CPASU_Journal = "C:\XX\XXX\Documents\Team docs\JMP Analysis\HTML"
    vSharePoint = "C:\XXX\XX\Documents\Team docs\JMP Analysis\Sample"

    Console.WriteLine("Begin pic upload... " & vbLf)
    fsoSource = CPASU_Journal & "\gfx\Image1.png"
    fsoDest = vSharePoint
    Console.Write(fsoSource)
    Console.Write(fsoDest)


    objFSO.CopyFile(fsoSource, fsoDest)
    Kill(fsoSource)
    End Sub

    End Module

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Copy paste error

    Why are you creating a FileSystemObject using late-binding when .NET has two different ways to copy files using only managed code? If you're using .NET then use .NET. Either use File.Copy or My.Computer.FileSystem.CopyFile.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    5

    Re: Copy paste error

    To be honest I was looking at a sample code and tried to replicate it...Appreciate it if u can tell me when to use filesystmobject code and when to use managed code...Also the differenced...

    thank u

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Copy paste error

    Always use managed code, i.e. .NET, if you can. Only use unmanaged code if there is no managed option.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    5

    Re: Copy paste error

    Ok here's an update.

    The destination is actually a sharepoint site. However it was not working with the FileStreamObject that I used earlier. At the same time this below code din't work either.

    My.Computer.FileSystem.CopyFile( _
    CPASU_Journal & "\gfx\Image1.png", _
    "http://moss.dell.com/sites/mscontacts/CPASU/default.aspx\Image1.png", _

    as it says links cannot be used in the syntax. Can anyone please tell me what function should I use for saving the file/image to a sharepoint site.

    Thanks,
    A

  6. #6

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    5

    Re: Copy paste error

    Here;s the code that I'm trying to use.

    vb Code:
    1. Module CPASU_SPC
    2.  
    3.     Sub Main()
    4.         Console.Title = "MOARW Programs"
    5.         Console.WriteLine("Begin Application" & vbLf)   'Writes text to console in a new line
    6.         Console.Beep()
    7.         Console.ReadLine()
    8.         Dim objFSO
    9.         Dim CPASU_Journal, vSharePoint, fsoSource, fsoDest
    10.         objFSO = CreateObject("Scripting.FileSystemObject")
    11.         CPASU_Journal = "C:\Users\**\Documents\Team docs\JMP Analysis\HTML"
    12.         vSharePoint = "http://moss.****/sites/***/***/Shared Documents"
    13.  
    14.  
    15.         fsoSource = CPASU_Journal & "\gfx\image1.png"
    16.         fsoDest = vSharePoint & "/image1.png"
    17.         objFSO.CopyFile(fsoSource, fsoDest)
    18.         Kill(fsoSource)
    19.     End Sub
    20.  
    21. End Module

    However I get the following exception when I run this program.

    Exception from HRESULT: 0x800A0034 (CTL_E_BADFILENAMEORNUMBER)


    Please help.

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Copy paste error

    "to a sharepoint site." --- ahhh.... that's the key right there...

    You're getting errors because you can't copy to an HTTP address... it simply doesn't work that way... if it did, people could upload all kinds of crap to websites everywhere.

    See if this is any help:
    http://blog.fpweb.net/transferring-f...places-drives/

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Copy paste error

    Something I jsut remembered... SP libraries are just shared folders that are formatted by the SP server... if you can get to the library, you should be able to View As Folder, from which you can get the //server/share/folder/subfolder/uh_huh_right_here path... which you can then use with your System.Io.File.Copy

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    5

    Re: Copy paste error

    I tried using the folder location than as the server address but the System.Io.File.Copy won't allow http locations as its parameters. I tried taking out the http but it doesn't do any pasting work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width