Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm working on a dataview web part in a MOSS 2007 environment which comes from a custom list. In this dataview web part, I'm wanting to link to the Attach Item form so users can attach some documentation for the item. What I'm struggling with is how to automatically trigger the UploadAttachment() javascript that executes when you navigate to EditForm.

My idea was to provide a clickable hyperlink in the dataview web part the links directly to the upload for for the corresponding list item. What are my options to achieve that result?

Edit: I can get there with the code below on the EditForm by passing in a query string parameter on my DVWP hyperlink, but I am wondering if there's a faster approach. The entire EditForm has to load before going to the upload screen.

<script type="text/javascript" src="/Resources/jquery.js"></script>
<script type="text/javascript" src="/Resources/SPServices.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var queryStringVals = $().SPServices.SPGetQueryString();
var up = queryStringVals["ToUpload"];
if (up = "1") {
    javascript:UploadAttachment();
    }

});
</script>
share|improve this question
    
Are you showing the toolbar (where you see the "Attach file" link)? Do you want the Attach File dialog to show on page load, or once the user does something? –  Marc D Anderson Aug 31 '11 at 2:13
    
I am showing the toolbar on the EditForm, but I feel that the user base this is for, the going to the EditForm and then clicking the attach file button isn't intuitive. I was hoping to streamline the number of clicks and take the user directly to the upload screen, as you'd expect if you click a link tha say Add Attachment in a DVWP. –  PirateEric Aug 31 '11 at 2:24
    
What you show above is probably what I'd do. I would worry a little bit that this form will work differently than any others, though. You're creating an inconsistent UX. –  Marc D Anderson Aug 31 '11 at 13:33
    
Well, the form is only going to work differently when navigated to through my DVWP as it's the only place that appends the QS parameter to it. –  PirateEric Aug 31 '11 at 14:29
add comment

2 Answers

You know that's going to be hard to do for a number of reasons. 1. The add attachment is just a hidden div activated with JavaScript. 2. a hidden input field stores the selected file paths until you save 3. The update method in the save button gathers those uploaded files and creates attachment entries. For a list form. To accomplish the same thing for DVWP, you might be able to what Mark Rackley suggested. Copy the divs and the hidden input. And then use the OTB save function to the list item. I don't know if this will work. I would try using SPServices to save the attachment using the divs as well. If Marc Anderson doesn't have a save attachment function, I'm sure he can whip one up :)

share|improve this answer
    
It isn't that I want to add the attachment functionality directly into the DVWP, but prvide a link directly to the upload screen when you visit the EditForm and click the Attach File link. –  PirateEric Aug 31 '11 at 11:56
    
Maybe I'm missing something here. But if you navigate to the EditForm it has an Add Attachment link already? What are you adding to improve that? If you don't want to build in the attachment functionality into the DVWP, the EditForm has to load up. There's a bit of state that must be read from the content database to be able to successfully save an entry including any attachments. If you want to bypass the standard edit you need a way to add attachments directly to the list item. SPServices is probably your best best. Adding attachments via lists.asmx is messy. Using lists.asmx is messy –  Brian Bedard Aug 31 '11 at 21:05
    
I'm basically trying to bypass the additional click on the editform page. –  PirateEric Sep 1 '11 at 1:03
add comment
up vote 0 down vote accepted

We ended up abandoning this piece of functionality.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.