This project is read-only.

Document.Upload

Sep 15, 2008 at 6:56 PM
Paul -

I have a web application with a simple button. Here's the code:

    protected void btnUpload_Click(object sender, EventArgs e)
    {
        try
        {
            // Set up upload notification
            Scribd.Net.Document.Uploaded += new EventHandler<DocumentEventArgs>(Document_Uploaded);

            // Send our PDF document to Scribd.
            Scribd.Net.Document settings = Scribd.Net.Document.Upload(@"C:\Documents and Settings\Desktop\Test.pdf", "pdf");
        }
        catch (Exception Ex)
        {
            lblError.Text = Ex.Message;
        }
    }

    protected void Document_Uploaded(object sender, DocumentEventArgs e)
    {
        try
        {
            Scribd.Net.Service.User.ReloadDocuments();
            BindMyDocuments(Scribd.Net.Service.User.Documents);
        }
        catch (Exception Ex)
        {
            lblError.Text = Ex.Message;
        }
    }

As you can see, I've hardcoded the document path. When I click the button, nothing happens.

When I add breakpoints and run the code in debug mode, it works.

Is there anything fundamentally wrong with the code, or what would account for this behaviour?

cheers,

Steve
Sep 15, 2008 at 8:25 PM
Could you post an example of how to use Document.Upload using a asp:FileUpload control so the user can browse their local HD from the web.

I've tried the following but that only returns the filename and not the Path:

flUpload.PostedFile.FileName

I also want to pick the documentType automatically from the FielUpload control, but I can do this by parsing the FileName to get the file extension.

Then I can use:

Scribd.Net.Document settings = Scribd.Net.Document.Upload(get the path from flUpload, parsed extension for documentType);

cheers,

Steve
Sep 30, 2008 at 9:26 PM
Paul -

Any update with this? I want to use this class library in a web project and allow document uploads and well as search/view.

Can you post an example of how to use Document.Upload using a asp:FileUpload control so the user can browse their local HD from the web.

cheers,

Steve
Coordinator
Sep 30, 2008 at 9:30 PM
Steve,

There's an example web application included in the source code.

Give that a shot -

- Paul
Sep 30, 2008 at 9:56 PM
Thanks for the quick reply.

I've looked in the example web app in the source code download, but I don't see any methods for uploading documents from a user's HD via a webform.

I gave it a try but since Document.Upload gets passed the path string, I couldn't get it working using a asp:FileUpload control. I want to make the end user click 'Browse', find the file and then click a submit button to upload to Scribd and refresh the local Document collection.

I have all the rest (search/view) working.

cheers,

Steve
Coordinator
Sep 30, 2008 at 10:04 PM
Edited Sep 30, 2008 at 10:13 PM
Steve,

The upload should take both a stream and a path name.  However, for the path name:

    string _pathToFile = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
    Document.Upload(_pathToFile);

This is out of my brain, so it's untested. 

- P


//edit //

P.s.:  http://msdn.microsoft.com/en-us/library/aa479405.aspx may help you out w/the uploading, etc.

Keep in mind, you'll have to have the file physically on the server to upload it to Scribd.  So the process is:   asp.FileUpload -> save to server directory -> get path of the uploaded file located on the server -> pass that path to the Document.Upload() method.

Developer
Nov 13, 2008 at 9:34 PM
Thanks for the tips Paul.

I've got it working as you suggest (client > server directory > get path > pass to Document.Upload() method. However, this means that the file is processed twice in memory, once to get it on the server, the next to add to scribd. I want to add it straight to scribd. I think the best way to do this would be to use System.IO.Stream instead of path. This is a little trickier.

I've tried the following but it doesn't want to work:

                    Dim strDocType As String = System.IO.Path.GetExtension(flUpload.PostedFile.FileName).ToLower()
                    Dim stream As Stream = flUpload.PostedFile.InputStream()
                    Dim Settings As Scribd.Net.Document = Nothing
                    Settings = Scribd.Net.Document.Upload(stream, strDocType)

Can you give me some clues on how to go direct to Scrib?

cheers,

Steve

Coordinator
Nov 14, 2008 at 12:14 PM
Steve,

I will have to look into this one.

- Paul
May 12, 2011 at 1:41 PM

i have the same probleme

can give me the correct code allowing upload a document and see the result in Scribd Viewer