Solved

How to call the code?

Posted on 2014-07-29
9
163 Views
Last Modified: 2014-07-29
I have a class file in my solution GetFile.cs
In here is a function called CopyFile()

In order to test CopyFile() I added a webform to the solution and in the page_load event in the code behind I am trying to call CopyFile() but no matter how I try intellisense is not offering it up.
I have tried CopyFile() and I have tried creating a new instance of GetFile as below but still I can't "reach" it

 public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GetFile theFile = new GetFile();

Open in new window


Here is CopyFile()

namespace HubbleDocs
{
    public class GetFile
    {

        
        public void CopyFile()
        {
...
}

Open in new window

0
Comment
Question by:QPR
  • 5
  • 4
9 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
Add a using statement to the top of your _default class:

using HubbleDocs;

Open in new window

0
 
LVL 29

Author Comment

by:QPR
Comment Utility
Sorry I should have posted the whole of default.aspx.cs as I already have that using statement

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HubbleDocs;

namespace HubbleDocs
{
    public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GetFile theFile = new GetFile();
            
        }
    }
}

Open in new window

0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
Is GetFile defined with the same assembly (i.e. project)?
0
 
LVL 29

Author Comment

by:QPR
Comment Utility
Yep, solution/project is called HubbleDocs which consists of GetFile.cs and default.aspx/cs (and a web service reference)
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 29

Author Comment

by:QPR
Comment Utility
solution files
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
Is it possible to post the entire GetFile definition?
0
 
LVL 29

Author Comment

by:QPR
Comment Utility
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.IO;


namespace HubbleDocs
{
    public class GetFile
    {

        
        public void CopyFile()
        {
            string webUrl = "http://xxx";
            FileCopy.Copy copyService = new FileCopy.Copy();
            copyService.Url = webUrl +"/_vti_bin/copy.asmx";
            NetworkCredential m_credentials = new NetworkCredential("x", "x", "x");
                 copyService.Credentials = m_credentials;

            //Source and Destination Document URLs
             string sourceUrl = "http://xxx/Documents/Sample.docx";
             string destinationUrl = "C:\\Documents\\Sample.doc";

            //Variables for Reading metadata’s of a document
             FileCopy.FieldInformation fieldInfo = new FileCopy.FieldInformation();
             FileCopy.FieldInformation[] fieldInfoArray = { fieldInfo };
             FileCopy.CopyResult cResult1 = new FileCopy.CopyResult();
             FileCopy.CopyResult cResult2 = new FileCopy.CopyResult();
             FileCopy.CopyResult[] cResultArray = { cResult1, cResult2 };

        

            //Receive a Document Contents  into Byte array (filecontents)
             byte[] fileContent; // no need to initialize the GetItem takes care of that.
             copyService.GetItem(sourceUrl, out fieldInfoArray, out fileContent);

            //Create a new file and write contents to that document
             FileStream fStream = new FileStream(destinationUrl, FileMode.Create, FileAccess.ReadWrite);
            fStream.Write(fileContent, 0, fileContent.Length);
            fStream.Close();
        }
    }
}

Open in new window

0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
Based on what you've posted, I don't see anything wrong. You should only have to invoke against the instance.

e.g.

GetFile theFile = new GetFile();

theFile.CopyFile();

Open in new window

0
 
LVL 29

Author Comment

by:QPR
Comment Utility
and now that I type it again I see it and it works!
So either my tired eyes didn't see it in the intellisense or the intellisense hadn't refreshed.
Oh well - all good now :)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now