2

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>
4
  • 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? Commented Aug 31, 2011 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. Commented Aug 31, 2011 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. Commented Aug 31, 2011 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. Commented Aug 31, 2011 at 14:29

2 Answers 2

1

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 :)

3
  • 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. Commented Aug 31, 2011 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 Commented Aug 31, 2011 at 21:05
  • I'm basically trying to bypass the additional click on the editform page. Commented Sep 1, 2011 at 1:03
0

We ended up abandoning this piece of functionality.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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