Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to call the code?

Posted on 2014-07-29
9
Medium Priority
?
178 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 75

Expert Comment

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

using HubbleDocs;

Open in new window

0
 
LVL 29

Author Comment

by:QPR
ID: 40228221
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 75

Expert Comment

by:käµfm³d 👽
ID: 40228227
Is GetFile defined with the same assembly (i.e. project)?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

Author Comment

by:QPR
ID: 40228232
Yep, solution/project is called HubbleDocs which consists of GetFile.cs and default.aspx/cs (and a web service reference)
0
 
LVL 29

Author Comment

by:QPR
ID: 40228237
solution files
0
 
LVL 75

Expert Comment

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

Author Comment

by:QPR
ID: 40228258
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 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 40228271
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
ID: 40228276
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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 …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

886 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