Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8237969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:39:14+00:00 2026-06-07T19:39:14+00:00

I’m able to drag a file URL from a NSTableView cell and drop it

  • 0

I’m able to drag a file URL from a NSTableView cell and drop it in any text editor. According to my understanding of Apple’s documentation though, when I drop the URL, the file should be copied to the drop location.

- (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard*)pboard {

    //for now putting specific file path in just to get it working
    NSString *filePath = @"/Users/Jackh/Desktop/Apple.png";
    [pboard declareTypes:[NSArray arrayWithObject:NSURLPboardType] owner:self];
    [[NSURL URLWithString:filePath] writeToPasteboard:pboard];

    return YES;

}

How do I get the file to copy from the filePath to the dropped location? It’s just moving filePath as text for now.

Any ideas?

Edit: I am now using this code

-(void)awakeFromNib {

    [self.tableView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:NO];

}

…

[self.tableView registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, NSFileContentsPboardType, nil]];

…

- (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard*)pboard {

    //for now putting specific file path in just to get it working
    NSString *filePath = @"/Users/Jackh/Desktop/Apple.png";
    [pboard declareTypes:[NSArray arrayWithObject:NSFileContentsPboardType] owner:nil];
    [pboard writeFileContents:filePath];

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:39:15+00:00Added an answer on June 7, 2026 at 7:39 pm

    If you want to force the green “+” to copy, just use NSDragOperationCopy (only) in the operation mask, disallowing other operations; e.g. in awakeFromNib:

    [self.tableView setDraggingSourceOperationMask:NSDragOperationCopy forLocal:NO];
    

    Here is the best way I could find to make your example work with the Finder:

    - (BOOL)
    tableView:(NSTableView *)tv
    writeRowsWithIndexes:(NSIndexSet*)rowIndexes
    toPasteboard:(NSPasteboard*)pboard {
        NSString *filePath = @"/Users/kevin/Desktop/1.png";
        [pboard declareTypes:[NSArray arrayWithObject:NSFilenamesPboardType]
                             owner:nil];
        [pboard setPropertyList:[NSArray arrayWithObject:filePath]
                                forType:NSFilenamesPboardType];
        return YES;
    }
    

    Note that Apple recommends using more modern APIs but I have found in cases like this they have a big side effect: they seem to cause files to be copied twice because URLs are magically copied in multiple forms. Having said that, your original URL example didn’t work because you should have used writeObjects: on the pasteboard instead of asking the URL to writeToPasteboard:. An example with URLs:

    - (BOOL)
    tableView:(NSTableView *)tv
    writeRowsWithIndexes:(NSIndexSet*)rowIndexes
    toPasteboard:(NSPasteboard*)pboard {
        NSString *filePath = @"/Users/kevin/Desktop/1.png";
        [pboard declareTypes:[NSArray arrayWithObject:NSURLPboardType]
                             owner:nil];
        [pboard writeObjects:[NSArray arrayWithObject:
                              [NSURL fileURLWithPath:filePath]]];
        return YES;
    }
    

    As I noted in other comments, if your drag is targeting a document instead of a file manager such as the Finder then it’s better to include the actual data for the file. Raw data can’t be misinterpreted by a document (i.e. the document has to insert the data directly, it can’t choose to insert a path string instead). On the other hand, raw-data drags don’t create files in the Finder for some reason so they’re useful mainly as something to add to the pasteboard as an alternative.

    Here is a way to use a UTI to declare the file type and call NSData to read a file (I tried this and it works, e.g. I can drag a table view row into a Rich Text document in TextEdit and see an image inserted into the window):

    - (BOOL)
    tableView:(NSTableView *)tv
    writeRowsWithIndexes:(NSIndexSet*)rowIndexes
    toPasteboard:(NSPasteboard*)pboard {
        NSString *filePath = @"/Users/kevin/Desktop/1.png";
        [pboard declareTypes:[NSArray arrayWithObject:@"public.png"]
                             owner:nil];
        [pboard setData:[NSData dataWithContentsOfFile:filePath]
                        forType:@"public.png"];
        return YES;
    }
    

    (I don’t know exactly why your writeFileContents: doesn’t work but the above does work and is basically the same thing.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.